Search in sources :

Example 1 with MessageSeataCodec

use of io.seata.serializer.seata.MessageSeataCodec in project seata by seata.

the class MergedWarpMessageCodec method doDecode.

private void doDecode(MergedWarpMessage mergedWarpMessage, ByteBuffer byteBuffer) {
    short msgNum = byteBuffer.getShort();
    List<AbstractMessage> msgs = new ArrayList<AbstractMessage>();
    for (int idx = 0; idx < msgNum; idx++) {
        short typeCode = byteBuffer.getShort();
        AbstractMessage abstractMessage = MessageCodecFactory.getMessage(typeCode);
        MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typeCode);
        messageCodec.decode(abstractMessage, byteBuffer);
        msgs.add(abstractMessage);
    }
    mergedWarpMessage.msgs = msgs;
}
Also used : AbstractMessage(io.seata.core.protocol.AbstractMessage) ArrayList(java.util.ArrayList) MessageSeataCodec(io.seata.serializer.seata.MessageSeataCodec)

Example 2 with MessageSeataCodec

use of io.seata.serializer.seata.MessageSeataCodec in project seata by seata.

the class MergedWarpMessageCodec method encode.

@Override
public <T> void encode(T t, ByteBuf out) {
    MergedWarpMessage mergedWarpMessage = (MergedWarpMessage) t;
    List<AbstractMessage> msgs = mergedWarpMessage.msgs;
    final ByteBuf buffer = Unpooled.buffer(1024);
    // write placeholder for content length
    buffer.writeInt(0);
    buffer.writeShort((short) msgs.size());
    for (final AbstractMessage msg : msgs) {
        final ByteBuf subBuffer = Unpooled.buffer(1024);
        short typeCode = msg.getTypeCode();
        MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typeCode);
        messageCodec.encode(msg, subBuffer);
        buffer.writeShort(msg.getTypeCode());
        buffer.writeBytes(subBuffer);
    }
    final int length = buffer.readableBytes();
    final byte[] content = new byte[length];
    // minus the placeholder length itself
    buffer.setInt(0, length - 4);
    buffer.readBytes(content);
    if (msgs.size() > 20) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("msg in one packet:" + msgs.size() + ",buffer size:" + content.length);
        }
    }
    out.writeBytes(content);
}
Also used : AbstractMessage(io.seata.core.protocol.AbstractMessage) MergedWarpMessage(io.seata.core.protocol.MergedWarpMessage) ByteBuf(io.netty.buffer.ByteBuf) MessageSeataCodec(io.seata.serializer.seata.MessageSeataCodec)

Example 3 with MessageSeataCodec

use of io.seata.serializer.seata.MessageSeataCodec in project seata by seata.

the class MergeResultMessageCodec method encode.

@Override
public <T> void encode(T t, ByteBuf out) {
    MergeResultMessage mergeResultMessage = (MergeResultMessage) t;
    AbstractResultMessage[] msgs = mergeResultMessage.getMsgs();
    int writeIndex = out.writerIndex();
    out.writeInt(0);
    out.writeShort((short) msgs.length);
    for (AbstractMessage msg : msgs) {
        // get messageCodec
        short typeCode = msg.getTypeCode();
        // put typeCode
        out.writeShort(typeCode);
        MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typeCode);
        messageCodec.encode(msg, out);
    }
    int length = out.readableBytes() - 4;
    out.setInt(writeIndex, length);
    if (msgs.length > 20) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("msg in one services merge packet:" + msgs.length + ",buffer size:" + length);
        }
    }
}
Also used : AbstractResultMessage(io.seata.core.protocol.AbstractResultMessage) AbstractMessage(io.seata.core.protocol.AbstractMessage) MergeResultMessage(io.seata.core.protocol.MergeResultMessage) MessageSeataCodec(io.seata.serializer.seata.MessageSeataCodec)

Example 4 with MessageSeataCodec

use of io.seata.serializer.seata.MessageSeataCodec in project seata by seata.

the class MergeResultMessageCodec method decode.

/**
 * Decode.
 *
 * @param mergeResultMessage the merge result message
 * @param byteBuffer         the byte buffer
 */
protected void decode(MergeResultMessage mergeResultMessage, ByteBuffer byteBuffer) {
    // msgs size
    short msgNum = byteBuffer.getShort();
    AbstractResultMessage[] msgs = new AbstractResultMessage[msgNum];
    for (int idx = 0; idx < msgNum; idx++) {
        short typeCode = byteBuffer.getShort();
        AbstractMessage abstractResultMessage = MessageCodecFactory.getMessage(typeCode);
        MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typeCode);
        messageCodec.decode(abstractResultMessage, byteBuffer);
        msgs[idx] = (AbstractResultMessage) abstractResultMessage;
    }
    mergeResultMessage.setMsgs(msgs);
}
Also used : AbstractResultMessage(io.seata.core.protocol.AbstractResultMessage) AbstractMessage(io.seata.core.protocol.AbstractMessage) MessageSeataCodec(io.seata.serializer.seata.MessageSeataCodec)

Aggregations

AbstractMessage (io.seata.core.protocol.AbstractMessage)4 MessageSeataCodec (io.seata.serializer.seata.MessageSeataCodec)4 AbstractResultMessage (io.seata.core.protocol.AbstractResultMessage)2 ByteBuf (io.netty.buffer.ByteBuf)1 MergeResultMessage (io.seata.core.protocol.MergeResultMessage)1 MergedWarpMessage (io.seata.core.protocol.MergedWarpMessage)1 ArrayList (java.util.ArrayList)1