示例#1
0
        public static void GetBytes(byte[] buffer, ref int offset, JToken token)
        {
            BitConverter.GetBytes(buffer, ref offset, (int)token.Type);
            switch (token.Type)
            {
            case JTokenType.Object:
                JObjectConverter.GetBytes(buffer, ref offset, (JObject)token);
                break;

            case JTokenType.Array:
                JObjectConverter.GetBytes(buffer, ref offset, (JArray)token);
                break;

            case JTokenType.Integer:
                BitConverter.GetBytes(buffer, ref offset, (int)token);
                break;

            case JTokenType.Boolean:
                BitConverter.GetBytes(buffer, ref offset, (bool)token);
                break;

            case JTokenType.Float:
                BitConverter.GetBytes(buffer, ref offset, (float)token);
                break;

            case JTokenType.String:
                BitConverter.GetBytes(buffer, ref offset, (string)token);
                break;

            default:
                throw new NotSupportedException($"can't match jobject type: {token.ToString()}");
            }
        }
示例#2
0
 public static void GetBytes(byte[] buffer, ref int offset, JArray jArray)
 {
     BitConverter.GetBytes(buffer, ref offset, jArray.Count);
     foreach (var token in jArray)
     {
         JObjectConverter.GetBytes(buffer, ref offset, token);
     }
 }
示例#3
0
 /// <summary>
 /// jobject byte compact
 /// 1. size(jobject and jarray)
 /// 2. key(only jobject)
 /// 3. type
 /// 4. value
 /// </summary>
 /// <param name="buffer"></param>
 /// <param name="offset"></param>
 /// <param name="jObject"></param>
 public static void GetBytes(byte[] buffer, ref int offset, JObject jObject)
 {
     BitConverter.GetBytes(buffer, ref offset, jObject.Count);
     foreach (var pair in jObject)
     {
         BitConverter.GetBytes(buffer, ref offset, pair.Key);
         JObjectConverter.GetBytes(buffer, ref offset, pair.Value);
     }
 }