use of io.seata.serializer.protobuf.generated.MergedWarpMessageProto in project seata by seata.
the class MergedWarpMessageConvertor method convert2Proto.
@Override
public MergedWarpMessageProto convert2Proto(MergedWarpMessage mergedWarpMessage) {
final short typeCode = mergedWarpMessage.getTypeCode();
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(MessageTypeProto.forNumber(typeCode)).build();
List<Any> lists = new ArrayList<>();
for (AbstractMessage msg : mergedWarpMessage.msgs) {
final PbConvertor pbConvertor = ProtobufConvertManager.getInstance().fetchConvertor(msg.getClass().getName());
lists.add(Any.pack((Message) pbConvertor.convert2Proto(msg)));
}
MergedWarpMessageProto mergedWarpMessageProto = MergedWarpMessageProto.newBuilder().setAbstractMessage(abstractMessage).addAllMsgs(lists).addAllMsgIds(mergedWarpMessage.msgIds).build();
return mergedWarpMessageProto;
}
use of io.seata.serializer.protobuf.generated.MergedWarpMessageProto in project seata by seata.
the class MergeMessageConvertorTest method test.
@Test
public void test() {
MergedWarpMessage mergedWarpMessage = new MergedWarpMessage();
final ArrayList<AbstractMessage> msgs = new ArrayList<>();
final GlobalBeginRequest globalBeginRequest = buildGlobalBeginRequest();
msgs.add(globalBeginRequest);
mergedWarpMessage.msgs = msgs;
MergedWarpMessageConvertor pbConvertor = new MergedWarpMessageConvertor();
MergedWarpMessageProto globalBeginRequestProto = pbConvertor.convert2Proto(mergedWarpMessage);
MergedWarpMessage model = pbConvertor.convert2Model(globalBeginRequestProto);
GlobalBeginRequest decodeModel = (GlobalBeginRequest) model.msgs.get(0);
assertThat(decodeModel.getTransactionName()).isEqualTo(globalBeginRequest.getTransactionName());
assertThat(decodeModel.getTimeout()).isEqualTo(globalBeginRequest.getTimeout());
assertThat(decodeModel.getTypeCode()).isEqualTo(globalBeginRequest.getTypeCode());
}
Aggregations