Exemplo n.º 1
0
 public byte[] ToProtobuf()
 {
     using (MemoryStream ms = new MemoryStream())
         using (pb::CodedOutputStream stream = new pb::CodedOutputStream(ms))
         {
             WriteTo(stream);
             stream.Flush();
             return(ms.ToArray());
         }
 }
Exemplo n.º 2
0
 public static byte[] ToProtobuf(this ConfigProto cp)
 {
     using (MemoryStream ms = new MemoryStream())
         using (pb::CodedOutputStream stream = new pb::CodedOutputStream(ms))
         {
             cp.WriteTo(stream);
             stream.Flush();
             return(ms.ToArray());
         }
 }
Exemplo n.º 3
0
 public static byte[] SerializeUDP(cProto.PACKETID packetType, pb::IMessage pbmsg)
 {
     byte[] pbbf;
     using (MemoryStream ms = new MemoryStream())
     {
         pb::CodedOutputStream s = new pb::CodedOutputStream(ms);
         pbmsg.WriteTo(s);
         s.Flush();
         pbbf = ms.ToArray();
         s.Dispose();
     }
     return(pbbf);
 }
Exemplo n.º 4
0
        public static byte[] Serialize(cProto.PACKETID packetType, pb::IMessage pbmsg)
        {
            int index = (int)packetType;

            byte[] pbbf;
            using (MemoryStream ms = new MemoryStream())
            {
                pb::CodedOutputStream s = new pb::CodedOutputStream(ms);
                pbmsg.WriteTo(s);
                s.Flush();
                pbbf = ms.ToArray();
                s.Dispose();
            }
            byte[] outarray = new byte[sizeof(short) + sizeof(short) + pbbf.Length];

            Array.Copy(BitConverter.GetBytes((short)index), outarray, sizeof(short));
            Array.Copy(BitConverter.GetBytes((short)pbbf.Length), 0, outarray, sizeof(short), sizeof(short));
            Array.Copy(pbbf, 0, outarray, sizeof(int), pbbf.Length);
            return(outarray);
        }