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;
}
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);
}
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);
}
}
}
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);
}
Aggregations