Ejemplo n.º 1
0
 public MessageProtocol(JsonObject dict, JsonObject serverProtos, JsonObject clientProtos)
 {
     foreach (string str in dict.Keys)
     {
         ushort num = Convert.ToUInt16(dict[str]);
         this.dict[str]  = num;
         this.abbrs[num] = str;
     }
     this.protobuf     = new Pomelo.Protobuf.Protobuf(clientProtos, serverProtos);
     this.encodeProtos = clientProtos;
     this.decodeProtos = serverProtos;
     this.reqMap       = new Dictionary <uint, string>();
 }
Ejemplo n.º 2
0
        public static void Run()
        {
            JsonObject encodeProtos = read("./protos.json");
            JsonObject obj3         = read("./msg.json");

            Pomelo.Protobuf.Protobuf protobuf = new Pomelo.Protobuf.Protobuf(encodeProtos, encodeProtos);
            foreach (string str in obj3.Keys)
            {
                JsonObject msg    = (JsonObject)obj3[str];
                byte[]     buffer = protobuf.encode(str, msg);
                protobuf.decode(str, buffer);
            }
            Console.WriteLine("finish protobuf test");
        }
        public static void Run()
        {
            JsonObject protos = read ("./protos.json");
            JsonObject msgs = read ("./msg.json");

            Protobuf protobuf = new Protobuf(protos, protos);

            ICollection<string> keys = msgs.Keys;

            foreach(string key in keys){
                JsonObject msg = (JsonObject)msgs[key];
                byte[] bytes = protobuf.encode(key, msg);
                JsonObject result = protobuf.decode(key, bytes);
            }

            Console.WriteLine("Protobuf test success!");
        }
        public static void Run()
        {
            JsonObject protos = read("../../json/rootProtos.json");
            JsonObject msgs = read("../../json/rootMsg.json");

            Protobuf protobuf = new Protobuf(protos, protos);

            ICollection<string> keys = msgs.Keys;

            foreach (string key in keys)
            {
                JsonObject msg = (JsonObject)msgs[key];
                byte[] bytes = protobuf.encode(key, msg);
                JsonObject result = protobuf.decode(key, bytes);
                if (!equal(msg, result))
                {
                    Console.WriteLine("protobuf test failed!");
                    return;
                }
            }

            Console.WriteLine("Protobuf test success!");
        }