/// <summary>
 /// 设置列表
 /// </summary>
 /// <param name="list">列表</param>
 internal void SetList(SubArrayStruct<JsonNodeStruct> list)
 {
     this._list = list.array;
     Int64 = list.Count;
     Type = TypeEnum.List;
 }
 /// <summary>
 /// 创建字典节点
 /// </summary>
 /// <param name="dictionary"></param>
 /// <returns></returns>
 public static JsonNodeStruct CreateDictionary(SubArrayStruct<KeyValueStruct<SubStringStruct, JsonNodeStruct>> dictionary)
 {
     var node = new JsonNodeStruct { Type = TypeEnum.Dictionary };
     node.SetDictionary(dictionary.GetArray(value => new KeyValueStruct<JsonNodeStruct, JsonNodeStruct>(new JsonNodeStruct { Type = TypeEnum.String, String = value.Key }, value.Value)).ToSubArray());
     return node;
 }
 /// <summary>
 /// 设置字典
 /// </summary>
 /// <param name="dictionary">字典</param>
 internal void SetDictionary(SubArrayStruct<KeyValueStruct<JsonNodeStruct, JsonNodeStruct>> dictionary)
 {
     this._dictionary = dictionary.array;
     Int64 = dictionary.Count;
     Type = TypeEnum.Dictionary;
 }
 /// <summary>
 /// 缓冲数组子串
 /// </summary>
 /// <param name="value">数组子串</param>
 /// <param name="pushPool">数组子串入池处理</param>
 public PushSubArrayStruct(SubArrayStruct<byte> value, pushPool<byte[]> pushPool)
 {
     Value = value;
     PushPool = pushPool;
 }
 /// <summary>
 /// 保存缓冲区
 /// </summary>
 /// <param name="buffer"></param>
 public void Push(SubArrayStruct<byte> buffer)
 {
     buffer.UnsafeSet(0, 0);
     Push(ref buffer._array);
 }
Esempio n. 6
0
 /// <summary>
 ///     字节流转换成JSON字符串
 /// </summary>
 /// <param name="jsonStream">JSON输出流</param>
 /// <param name="buffer">字节流数组</param>
 public static unsafe void ToJson(CharStreamPlus jsonStream, SubArrayStruct<byte> buffer)
 {
     if (buffer.Array == null) AjaxPlus.WriteNull(jsonStream);
     else if (buffer.Count == 0) AjaxPlus.WriteArray(jsonStream);
     else
     {
         fixed (byte* bufferFixed = buffer.Array)
         {
             var start = bufferFixed + buffer.StartIndex;
             ToJson(jsonStream, start, start + buffer.Count);
         }
     }
 }
 /// <summary>
 ///     模拟javascript解码函数unescape
 /// </summary>
 /// <param name="value">原字符串</param>
 /// <returns>unescape解码后的字符串</returns>
 internal static unsafe SubStringStruct JavascriptUnescape(SubArrayStruct<byte> value)
 {
     if (value.Count != 0)
     {
         var newValue = StringPlus.FastAllocateString(value.Count);
         fixed (char* newValueFixed = newValue)
         fixed (byte* valueFixed = value.Array)
         {
             byte* start = valueFixed + value.StartIndex, end = start + value.Count;
             var write = newValueFixed;
             while (start != end && *start != '%')
             {
                 *write++ = *start == 0 ? ' ' : (char) *start;
                 ++start;
             }
             if (start != end)
             {
                 do
                 {
                     if (*++start == 'u')
                     {
                         uint code = (uint) (*++start - '0'), number = (uint) (*++start - '0');
                         if (code > 9) code = ((code - ('A' - '0')) & 0xffdfU) + 10;
                         if (number > 9) number = ((number - ('A' - '0')) & 0xffdfU) + 10;
                         code <<= 12;
                         code += (number << 8);
                         if ((number = (uint) (*++start - '0')) > 9)
                             number = ((number - ('A' - '0')) & 0xffdfU) + 10;
                         code += (number << 4);
                         number = (uint) (*++start - '0');
                         code += (number > 9 ? (((number - ('A' - '0')) & 0xffdfU) + 10) : number);
                         *write++ = code == 0 ? ' ' : (char) code;
                     }
                     else
                     {
                         uint code = (uint) (*start - '0'), number = (uint) (*++start - '0');
                         if (code > 9) code = ((code - ('A' - '0')) & 0xffdfU) + 10;
                         code = (number > 9 ? (((number - ('A' - '0')) & 0xffdfU) + 10) : number) + (code << 4);
                         *write++ = code == 0 ? ' ' : (char) code;
                     }
                     while (++start < end && *start != '%') *write++ = *start == 0 ? ' ' : (char) *start;
                 } while (start < end);
                 return SubStringStruct.Unsafe(newValue, 0, (int) (write - newValueFixed));
             }
             return SubStringStruct.Unsafe(newValue, 0, value.Count);
         }
     }
     return default(SubStringStruct);
 }
 /// <summary>
 ///     写入数据
 /// </summary>
 /// <param name="data">数据</param>
 public void Write(SubArrayStruct<byte> data)
 {
     var count = data.Count;
     if (count != 0)
     {
         PrepLength(count);
         fixed (byte* dataFixed = data.Array)
         {
             MemoryUnsafe.Copy(dataFixed + data.StartIndex, Data + Length, count);
         }
         LengthBase += count;
     }
 }