Ejemplo n.º 1
0
 public static unsafe void ToString(Guid value, TmphCharStream jsonStream)
 {
     var guid = new TmphGuid { Value = value };
     jsonStream.PrepLength(38);
     var data = (byte*)jsonStream.CurrentChar;
     int high = guid.Byte3 >> 4, low = guid.Byte3 & 15;
     *(char*)data = Quote;
     *(char*)(data + sizeof(char)) = (char)(high < 10 ? high + '0' : (high + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 2) = (char)(low < 10 ? low + '0' : (low + ('0' + 'A' - '9' - 1)));
     high = guid.Byte2 >> 4;
     low = guid.Byte2 & 15;
     *(char*)(data + sizeof(char) * 3) = (char)(high < 10 ? high + '0' : (high + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 4) = (char)(low < 10 ? low + '0' : (low + ('0' + 'A' - '9' - 1)));
     high = guid.Byte1 >> 4;
     low = guid.Byte1 & 15;
     *(char*)(data + sizeof(char) * 5) = (char)(high < 10 ? high + '0' : (high + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 6) = (char)(low < 10 ? low + '0' : (low + ('0' + 'A' - '9' - 1)));
     high = guid.Byte0 >> 4;
     low = guid.Byte0 & 15;
     *(char*)(data + sizeof(char) * 7) = (char)(high < 10 ? high + '0' : (high + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 8) = (char)(low < 10 ? low + '0' : (low + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 9) = '-';
     high = guid.Byte5 >> 4;
     low = guid.Byte5 & 15;
     *(char*)(data + sizeof(char) * 10) = (char)(high < 10 ? high + '0' : (high + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 11) = (char)(low < 10 ? low + '0' : (low + ('0' + 'A' - '9' - 1)));
     high = guid.Byte4 >> 4;
     low = guid.Byte4 & 15;
     *(char*)(data + sizeof(char) * 12) = (char)(high < 10 ? high + '0' : (high + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 13) = (char)(low < 10 ? low + '0' : (low + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 14) = '-';
     high = guid.Byte7 >> 4;
     low = guid.Byte7 & 15;
     *(char*)(data + sizeof(char) * 15) = (char)(high < 10 ? high + '0' : (high + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 16) = (char)(low < 10 ? low + '0' : (low + ('0' + 'A' - '9' - 1)));
     high = guid.Byte6 >> 4;
     low = guid.Byte6 & 15;
     *(char*)(data + sizeof(char) * 17) = (char)(high < 10 ? high + '0' : (high + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 18) = (char)(low < 10 ? low + '0' : (low + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 19) = '-';
     high = guid.Byte8 >> 4;
     low = guid.Byte8 & 15;
     *(char*)(data + sizeof(char) * 20) = (char)(high < 10 ? high + '0' : (high + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 21) = (char)(low < 10 ? low + '0' : (low + ('0' + 'A' - '9' - 1)));
     high = guid.Byte9 >> 4;
     low = guid.Byte9 & 15;
     *(char*)(data + sizeof(char) * 22) = (char)(high < 10 ? high + '0' : (high + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 23) = (char)(low < 10 ? low + '0' : (low + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 24) = '-';
     high = guid.Byte10 >> 4;
     low = guid.Byte10 & 15;
     *(char*)(data + sizeof(char) * 25) = (char)(high < 10 ? high + '0' : (high + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 26) = (char)(low < 10 ? low + '0' : (low + ('0' + 'A' - '9' - 1)));
     high = guid.Byte11 >> 4;
     low = guid.Byte11 & 15;
     *(char*)(data + sizeof(char) * 27) = (char)(high < 10 ? high + '0' : (high + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 28) = (char)(low < 10 ? low + '0' : (low + ('0' + 'A' - '9' - 1)));
     high = guid.Byte12 >> 4;
     low = guid.Byte12 & 15;
     *(char*)(data + sizeof(char) * 29) = (char)(high < 10 ? high + '0' : (high + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 30) = (char)(low < 10 ? low + '0' : (low + ('0' + 'A' - '9' - 1)));
     high = guid.Byte13 >> 4;
     low = guid.Byte13 & 15;
     *(char*)(data + sizeof(char) * 31) = (char)(high < 10 ? high + '0' : (high + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 32) = (char)(low < 10 ? low + '0' : (low + ('0' + 'A' - '9' - 1)));
     high = guid.Byte14 >> 4;
     low = guid.Byte14 & 15;
     *(char*)(data + sizeof(char) * 33) = (char)(high < 10 ? high + '0' : (high + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 34) = (char)(low < 10 ? low + '0' : (low + ('0' + 'A' - '9' - 1)));
     high = guid.Byte15 >> 4;
     low = guid.Byte15 & 15;
     *(char*)(data + sizeof(char) * 35) = (char)(high < 10 ? high + '0' : (high + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 36) = (char)(low < 10 ? low + '0' : (low + ('0' + 'A' - '9' - 1)));
     *(char*)(data + sizeof(char) * 37) = Quote;
     jsonStream.Unsafer.AddLength(38);
 }
Ejemplo n.º 2
0
 public static unsafe void ToString(byte value, TmphCharStream jsonStream)
 {
     if (value == 0) jsonStream.Write('0');
     else
     {
         jsonStream.PrepLength(4);
         var data = (byte*)jsonStream.CurrentChar;
         var nextValue = value >> 4;
         *(char*)data = '0';
         *(char*)(data + sizeof(char)) = 'x';
         *(char*)(data + sizeof(char) * 2) =
             (char)(nextValue < 10 ? nextValue + '0' : (nextValue + ('0' + 'A' - '9' - 1)));
         *(char*)(data + sizeof(char) * 3) =
             (char)((value &= 15) < 10 ? value + '0' : (value + ('0' + 'A' - '9' - 1)));
         jsonStream.Unsafer.AddLength(4);
     }
 }
Ejemplo n.º 3
0
 public static unsafe void ToStringNotNull(DateTime time, TmphCharStream jsonStream)
 {
     char* chars = stackalloc char[20];
     var index = toString((time.Ticks - JavascriptMinTimeTicks) / TmphDate.MillisecondTicks, chars);
     jsonStream.PrepLength(index.Value + DateStart.Length + 1);
     var unsafeStraem = jsonStream.Unsafer;
     fixed (char* dataFixed = DateStart) unsafeStraem.Write(dataFixed, DateStart.Length);
     unsafeStraem.Write(chars + index.Key, index.Value);
     unsafeStraem.Write(DateEnd);
 }
Ejemplo n.º 4
0
 public static unsafe void ToString(ulong value, TmphCharStream jsonStream, bool isMaxToString = true)
 {
     if (value <= maxValue || !isMaxToString)
     {
         char* chars = stackalloc char[20];
         var index = toString(value, chars);
         jsonStream.Write(chars + index.Key, index.Value);
     }
     else
     {
         var unsafeStraem = jsonStream.Unsafer;
         jsonStream.PrepLength(22);
         unsafeStraem.Write(Quote);
         TmphNumber.ToString(value, jsonStream);
         unsafeStraem.Write(Quote);
     }
 }
Ejemplo n.º 5
0
 public static unsafe void ToString(sbyte value, TmphCharStream jsonStream)
 {
     if (value == 0) jsonStream.Write('0');
     else
     {
         char* chars = stackalloc char[6];
         if (value < 0)
         {
             if (value == -128)
             {
                 jsonStream.PrepLength(4);
                 var unsafeStream = jsonStream.Unsafer;
                 unsafeStream.Write('-');
                 unsafeStream.Write('1');
                 unsafeStream.Write('2');
                 unsafeStream.Write('8');
             }
             else
             {
                 toString((sbyte)-value, chars);
                 jsonStream.Write(chars + 1, 5);
             }
         }
         else
         {
             toString(value, chars);
             jsonStream.Write(chars + 2, 4);
         }
     }
 }
Ejemplo n.º 6
0
 public static unsafe void WriteArray(TmphCharStream jsonStream)
 {
     jsonStream.PrepLength(2);
     var data = (byte*)jsonStream.CurrentChar;
     *(char*)data = '[';
     *(char*)(data + sizeof(char)) = ']';
     jsonStream.Unsafer.AddLength(2);
 }
Ejemplo n.º 7
0
 public static unsafe void WriteNaN(TmphCharStream jsonStream)
 {
     jsonStream.PrepLength(3);
     var data = (byte*)jsonStream.CurrentChar;
     *(char*)data = 'N';
     *(char*)(data + sizeof(char)) = 'a';
     *(char*)(data + sizeof(char) * 2) = 'N';
     jsonStream.Unsafer.AddLength(3);
 }
Ejemplo n.º 8
0
 public static void ToString(TmphSubString value, TmphCharStream jsonStream)
 {
     if (value.value == null) WriteNull(jsonStream);
     else
     {
         jsonStream.PrepLength(value.Length + 2);
         jsonStream.Unsafer.Write(Quote);
         jsonStream.Write(value);
         jsonStream.Unsafer.Write(Quote);
     }
 }
Ejemplo n.º 9
0
 public static void ToString(string value, TmphCharStream jsonStream)
 {
     jsonStream.PrepLength(value.Length() + 2);
     jsonStream.Unsafer.Write(Quote);
     jsonStream.Write(value);
     jsonStream.Unsafer.Write(Quote);
 }
Ejemplo n.º 10
0
 public static void ToString(char value, TmphCharStream jsonStream)
 {
     jsonStream.PrepLength(3);
     var unsafeStream = jsonStream.Unsafer;
     unsafeStream.Write(Quote);
     unsafeStream.Write(value);
     unsafeStream.Write(Quote);
 }
 /// <summary>
 ///     数值转字符串
 /// </summary>
 /// <param name="value">数值</param>
 /// <param name="charStream">字符流</param>
 internal static void ToString(short value, TmphCharStream charStream)
 {
     charStream.PrepLength(6);
     charStream.Unsafer.AddLength(toString(value, charStream.CurrentChar));
 }
 /// <summary>
 ///     数值转字符串
 /// </summary>
 /// <param name="value">数值</param>
 /// <param name="charStream">字符流</param>
 internal static void ToString(sbyte value, TmphCharStream charStream)
 {
     charStream.PrepLength(4);
     charStream.Unsafer.AddLength(toString(value, charStream.Char + charStream.Length));
 }