public static byte[] FinalizeProtoBuf(object proto, ushort packetid) { byte[] protobuff; using (var ms = new System.IO.MemoryStream()) { ProtoBuf.Serializer.Serialize(ms, proto); protobuff = ms.ToArray(); byte[] buffer; buffer = new byte[12 + protobuff.Length]; System.Buffer.BlockCopy(protobuff, 0, buffer, 4, protobuff.Length); Writer.Write(buffer.Length - 8, 0, buffer); Writer.Write(packetid, 2, buffer); return buffer; } }