public static <T> byte[] toByteArray(T message, Schema<T> schema, boolean numeric, LinkedBuffer buffer)
    {
        if (buffer.start != buffer.offset)
        {
            throw new IllegalArgumentException("Buffer previously used and had not been reset.");
        }

        MsgpackXOutput output = new MsgpackXOutput(buffer, numeric, schema);

        try
        {
            LinkedBuffer objectHeader = output.writeStartObject();
            schema.writeTo(output, message);

            if (output.isLastRepeated())
            {
                output.writeEndArray();
            }

            output.writeEndObject(objectHeader);

        }
        catch (IOException e)
        {
            throw new RuntimeException("Serializing to a byte array threw an IOException", e);
        }

        return output.toByteArray();
    }
Custom eXtream IO util to serialize and deserialize MessagePack format

@author Alex Shvid
protostuff-msgpack/src/main/java/io/protostuff/MsgpackXIOUtil.java