Continuous buffer

hello everyone
I want to implement a new custom protocol. Because I had already worked with fmb120 device with Teltonika protocol, I used this protocol for example to start. In this protocol and device, when the connection with the server is not established, the positions are saved and data will be sent later when the socket is connected. I checked the Traccar server log. In such cases, two or more continuous buffers contain these data. My question is, how are these continuous buffers detected and merged? In my own research, I found out that this is done in framedecoder, but I didn't understand exactly how it works. I will put the frameDecodercode for the Teltonika protocol so that it can be referred to more easily.
Program version 5.5

public class TeltonikaFrameDecoder extends BaseFrameDecoder {

    private static final int MESSAGE_MINIMUM_LENGTH = 12;

    @Override
    protected Object decode(
            ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {

        while (buf.isReadable() && buf.getByte(buf.readerIndex()) == (byte) 0xff) {
            buf.skipBytes(1);
        }

        if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) {
            return null;
        }

        int length = buf.getUnsignedShort(buf.readerIndex());
        if (length > 0) {
            if (buf.readableBytes() >= (length + 2)) {
                return buf.readRetainedSlice(length + 2);
            }
        } else {
            int dataLength = buf.getInt(buf.readerIndex() + 4);
            if (buf.readableBytes() >= (dataLength + 12)) {
                return buf.readRetainedSlice(dataLength + 12);
            }
        }

        return null;
    }

}
Anton Tananaeva year ago

It is done in frame decoder. I would recommend reading Netty documentation about it.