Search in sources :

Example 1 with MergedWarpMessageProto

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;
}
Also used : MergedWarpMessageProto(io.seata.serializer.protobuf.generated.MergedWarpMessageProto) AbstractMessage(io.seata.core.protocol.AbstractMessage) AbstractMessage(io.seata.core.protocol.AbstractMessage) Message(com.google.protobuf.Message) MergedWarpMessage(io.seata.core.protocol.MergedWarpMessage) ArrayList(java.util.ArrayList) Any(com.google.protobuf.Any) AbstractMessageProto(io.seata.serializer.protobuf.generated.AbstractMessageProto)

Example 2 with 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());
}
Also used : MergedWarpMessageProto(io.seata.serializer.protobuf.generated.MergedWarpMessageProto) GlobalBeginRequest(io.seata.core.protocol.transaction.GlobalBeginRequest) AbstractMessage(io.seata.core.protocol.AbstractMessage) ArrayList(java.util.ArrayList) MergedWarpMessage(io.seata.core.protocol.MergedWarpMessage) Test(org.junit.jupiter.api.Test)

Aggregations

AbstractMessage (io.seata.core.protocol.AbstractMessage)2 MergedWarpMessage (io.seata.core.protocol.MergedWarpMessage)2 MergedWarpMessageProto (io.seata.serializer.protobuf.generated.MergedWarpMessageProto)2 ArrayList (java.util.ArrayList)2 Any (com.google.protobuf.Any)1 Message (com.google.protobuf.Message)1 GlobalBeginRequest (io.seata.core.protocol.transaction.GlobalBeginRequest)1 AbstractMessageProto (io.seata.serializer.protobuf.generated.AbstractMessageProto)1 Test (org.junit.jupiter.api.Test)1