static byte[] ToProtocolMessage(int id, byte[] body)
        {
            var fbb     = new FlatBufferBuilder(body.Length + InitialBufferSize);
            var bodyPos = ProtocolMessage.CreateBodyVector(fbb, body);

            ProtocolMessage.StartProtocolMessage(fbb);
            ProtocolMessage.AddId(fbb, id);
            ProtocolMessage.AddBody(fbb, bodyPos);
            var msg = ProtocolMessage.EndProtocolMessage(fbb);

            ProtocolMessage.FinishProtocolMessageBuffer(fbb, msg);

            var buffer     = fbb.DataBuffer;
            var bufferSize = buffer.Length - buffer.Position;
            var head       = BitConverter.GetBytes(bufferSize);

            var bytes = new byte[head.Length + bufferSize];

            Array.Copy(head, 0, bytes, 0, head.Length);
            Array.Copy(buffer.Data, buffer.Position, bytes, head.Length, bufferSize);

            return(bytes);
        }
 public static ProtocolMessage GetRootAsProtocolMessage(ByteBuffer _bb, ProtocolMessage obj)
 {
     return(obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }