@Override
    public byte[] toByteArray() {

        // write last chunk message id
        MessageIdData msgId = super.writeMessageIdData(null, -1, 0);

        // write first chunk message id
        msgId.setFirstChunkMessageId();
        firstChunkMsgId.writeMessageIdData(msgId.getFirstChunkMessageId(), -1, 0);

        int size = msgId.getSerializedSize();
        ByteBuf serialized = Unpooled.buffer(size, size);
        msgId.writeTo(serialized);

        return serialized.array();
    }
@Test
    public void serializeAndDeserializeTest() throws IOException {
        ChunkMessageIdImpl chunkMessageId = new ChunkMessageIdImpl(
                new MessageIdImpl(0, 0, 0),
                new MessageIdImpl(1, 1, 1)
        );
        byte[] serialized = chunkMessageId.toByteArray();
        ChunkMessageIdImpl deserialized = (ChunkMessageIdImpl) MessageIdImpl.fromByteArray(serialized);
        assertEquals(deserialized, chunkMessageId);
    }