Esempio n. 1
0
        public static string Pb2String(pb::IMessage retMsg)
        {
            pb::CodedOutputStream cos = new pb::CodedOutputStream(bytesPBBuffer);

            retMsg.WriteTo(cos);
            string ret = Util.Byte2String(bytesPBBuffer, 0, cos.Position);

            return(ret);
        }
Esempio n. 2
0
        public static byte[] Pb2Byte(pb::IMessage retMsg)
        {
            pb::CodedOutputStream cos = new pb::CodedOutputStream(bytesPBBuffer);

            retMsg.WriteTo(cos);
            byte[] ret = new byte[cos.Position];
            Array.Copy(bytesPBBuffer, 0, ret, 0, cos.Position);

            return(ret);
        }
Esempio 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);
 }
Esempio 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);
        }