Пример #1
0
        /// <summary>
        /// Decode each simple type in message.
        /// </summary>
        private JsonNode decodeProp(string type, JsonNode proto)
        {
            switch (type)
            {
            case "uInt32":
                // TODO: DZÔڵĴíÎó
                return(new JsonData((int)Decoder.decodeUInt32(this.getBytes())));

            case "int32":
            case "sInt32":
                return(new JsonData(Decoder.decodeSInt32(this.getBytes())));

            case "float":
                return(new JsonData(this.decodeFloat()));

            case "double":
                return(new JsonData(this.decodeDouble()));

            case "string":
                return(new JsonData(this.decodeString()));

            default:
                return(this.decodeObject(type, proto));
            }
        }
Пример #2
0
        private object decodeProp(string type, int len)
        {
            switch (type)
            {
            case "uint32":
                return(Decoder.decodeUInt32(getBytes()));

            case "int32":
            case "sint32":
                return(Decoder.decodeSInt32(getBytes()));

            case "uint64":
                return(Decoder.decodeUInt64(getBytes()));

            case "int64":
            case "sint64":
                return(Decoder.decodeSInt64(getBytes()));

            case "float":
                return(decodeFloat());

            case "double":
                return(decodeDouble());

            case "string":
                return(decodeString());

            case "bool":
                return(decodeBool());

            default:
                return(decodeObject(type, protos, len));
            }
        }
Пример #3
0
        public static int decodeSInt32(byte[] bytes)
        {
            uint num1 = Decoder.decodeUInt32(bytes);
            int  num2 = (int)(num1 % 2U) == 1 ? -1 : 1;

            return(Convert.ToInt32((long)((num1 % 2U + num1) / 2U) * (long)num2));
        }
Пример #4
0
        /// <summary>
        /// Decode array in message.
        /// </summary>
        //private void decodeArray(List<object> list, string type, JsonData proto){
        //	if (this.util.isSimpleType(type)) {
        //              int length = (int)Decoder.decodeUInt32(this.getBytes());
        //		for(int i = 0; i < length; i++) {
        //                  list.Add(this.decodeProp(type, null));
        //              }
        //	} else {
        //              list.Add(this.decodeProp(type, proto));
        //          }
        //      }

        /// <summary>
        /// Decode each simple type in message.
        /// </summary>
        private object decodeProp(string type, JsonData proto)
        {
            switch (type)
            {
            case "uInt32":
                return(Decoder.decodeUInt32(this.getBytes()));

            case "int32":
            case "sInt32":
                return(Decoder.decodeSInt32(this.getBytes()));

            case "float":
                //object xx = this.decodeFloat();
                //return System.Convert.ToDouble(xx);
                return(this.decodeFloat());

            case "double":
                return(this.decodeDouble());

            case "string":
                return(this.decodeString());

            default:
                return(this.decodeObject(type, proto));
            }
        }
Пример #5
0
        private uint decodeUInt32()
        {
            int  length;
            uint ret = Decoder.decodeUInt32(this.offset, this.buffer, out length);

            this.offset += length;
            return(ret);
        }
Пример #6
0
        //Decode string type.
        private string decodeString()
        {
            int    length     = (int)Decoder.decodeUInt32(this.getBytes());
            string msg_string = Encoding.UTF8.GetString(this.buffer, this.offset, length);

            this.offset += length;
            return(msg_string);
        }
Пример #7
0
        private string decodeString()
        {
            int    count   = (int)Decoder.decodeUInt32(this.getBytes());
            string @string = Encoding.UTF8.GetString(this.buffer, this.offset, count);

            this.offset += count;
            return(@string);
        }
Пример #8
0
        //Get the type and tag.
        private Dictionary <string, int> getHead()
        {
            int tag = (int)Decoder.decodeUInt32(this.getBytes());
            Dictionary <string, int> head = new Dictionary <string, int>();

            head.Add("type", tag & 0x7);
            head.Add("tag", tag >> 3);
            return(head);
        }
Пример #9
0
        private void decodeArray(JArray list, string type)
        {
            uint length    = Decoder.decodeUInt32(getBytes());
            int  curOffset = offset;

            while (offset < curOffset + length)
            {
                list.Add(decodeProp(type, curOffset + Convert.ToInt32(length)));
            }
        }
Пример #10
0
        private JsonObject decodeObject(string type, JsonObject proto)
        {
            object obj1;
            object obj2;

            if (proto == null || !proto.TryGetValue("__messages", out obj1) || !((JsonObject)obj1).TryGetValue(type, out obj2) && !this.protos.TryGetValue("message " + type, out obj2))
            {
                return(new JsonObject());
            }
            int num = (int)Decoder.decodeUInt32(this.getBytes());

            return(this.decodeMsg(new JsonObject(), (JsonObject)obj2, this.offset + num));
        }
Пример #11
0
 /// <summary>
 /// Decode array in message.
 /// </summary>
 private void decodeArray(List <object> list, string type, JSONNode proto)
 {
     if (this.util.isSimpleType(type))
     {
         int length = (int)Decoder.decodeUInt32(this.getBytes());
         for (int i = 0; i < length; i++)
         {
             list.Add(this.decodeProp(type, null));
         }
     }
     else
     {
         list.Add(this.decodeProp(type, proto));
     }
 }
Пример #12
0
 private void decodeArray(List <object> list, string type, JsonObject proto)
 {
     if (this.util.isSimpleType(type))
     {
         int num = (int)Decoder.decodeUInt32(this.getBytes());
         for (int index = 0; index < num; ++index)
         {
             list.Add(this.decodeProp(type, (JsonObject)null));
         }
     }
     else
     {
         list.Add(this.decodeProp(type, proto));
     }
 }
Пример #13
0
        private Dictionary <string, int> getHead()
        {
            int num = (int)Decoder.decodeUInt32(this.getBytes());

            return(new Dictionary <string, int>()
            {
                {
                    "type",
                    num & 7
                },
                {
                    "tag",
                    num >> 3
                }
            });
        }
Пример #14
0
        //Decode the user-defined object type in message.
        private JObject decodeObject(string type, JObject proto, int len)
        {
            if (proto == null)
            {
                return(new JObject());
            }

            if (len == 0)
            {
                len = offset + (int)Decoder.decodeUInt32(getBytes());
            }

            JObject subProto = util.GetProtoMessage(proto, type);
            JObject msg      = new JObject();

            return(decodeMsg(msg, subProto, len));
        }
Пример #15
0
 //Decode the user-defined object type in message.
 private JSONNode decodeObject(string type, JSONNode proto)
 {
     if (proto != null)
     {
         object __messages;
         if (proto.TryGetValue("__messages", out __messages))
         {
             object _type;
             if (((JSONNode)__messages).TryGetValue(type, out _type) || protos.TryGetValue("message " + type, out _type))
             {
                 int      l   = (int)Decoder.decodeUInt32(this.getBytes());
                 JSONNode msg = new JSONClass();
                 return(this.decodeMsg(msg, (JSONNode)_type, this.offset + l));
             }
         }
     }
     return(new JSONClass());
 }
Пример #16
0
 //Decode the user-defined object type in message.
 private JsonNode decodeObject(string type, JsonNode proto)
 {
     if (proto != null)
     {
         JsonNode __messages = null;
         if (proto.TryGetValue("__messages", out __messages))
         {
             JsonNode _type = null;
             if (__messages.TryGetValue(type, out _type) || protos.TryGetValue("message " + type, out _type))
             {
                 int      l   = (int)Decoder.decodeUInt32(this.getBytes());
                 JsonNode msg = new JsonClass();
                 return(this.decodeMsg(msg, _type, this.offset + l));
             }
         }
     }
     return(new JsonClass());
 }
Пример #17
0
        /// <summary>
        /// Decode each simple type in message.
        /// </summary>
        private object decodeProp(string type, JSONNode proto)
        {
            switch (type)
            {
            case "uInt32":
                return(Decoder.decodeUInt32(this.getBytes()));

            case "int32":
            case "sInt32":
                return(Decoder.decodeSInt32(this.getBytes()));

            case "float":
                return(this.decodeFloat());

            case "double":
                return(this.decodeDouble());

            case "string":
                return(this.decodeString());

            default:
                return(this.decodeObject(type, proto));
            }
        }
Пример #18
0
        public static uint decodeUInt32(byte[] bytes)
        {
            int length;

            return(Decoder.decodeUInt32(0, bytes, out length));
        }