/// <summary> /// 数值转字符串 /// </summary> /// <param name="value">数值</param> /// <param name="charStream">字符流</param> internal static void ToString(short value, CharStreamPlus charStream) { charStream.PrepLength(6); charStream.Unsafer.AddLength(ToString(value, charStream.CurrentChar)); }
public static unsafe void WriteObject(CharStreamPlus jsonStream) { jsonStream.PrepLength(2); var data = (byte*) jsonStream.CurrentChar; *(char*) data = '{'; *(char*) (data + sizeof (char)) = '}'; jsonStream.Unsafer.AddLength(2); }
/// <summary> /// 数值转字符串 /// </summary> /// <param name="value">数值</param> /// <param name="charStream">字符流</param> internal static void ToString(sbyte value, CharStreamPlus charStream) { charStream.PrepLength(4); charStream.Unsafer.AddLength(ToString(value, charStream.Char + charStream.Length)); }
public static unsafe void ToStringNotNull(DateTime time, CharStreamPlus jsonStream) { char* chars = stackalloc char[20]; var index = ToString((time.Ticks - JavascriptMinTimeTicks)/DatePlus.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); }
public static unsafe void WriteNull(CharStreamPlus jsonStream) { jsonStream.PrepLength(4); var data = (byte*) jsonStream.CurrentChar; *(char*) data = 'n'; *(char*) (data + sizeof (char)) = 'u'; *(char*) (data + sizeof (char)*2) = 'l'; *(char*) (data + sizeof (char)*3) = 'l'; jsonStream.Unsafer.AddLength(4); }
public static void ToString(string value, CharStreamPlus jsonStream) { jsonStream.PrepLength(value.Length + 2); jsonStream.Unsafer.Write(Quote); jsonStream.WriteBase(value); jsonStream.Unsafer.Write(Quote); }
public static void ToString(SubStringStruct value, CharStreamPlus jsonStream) { if (value.Value == null) WriteNull(jsonStream); else { jsonStream.PrepLength(value.Length + 2); jsonStream.Unsafer.Write(Quote); jsonStream.WriteBase(value); jsonStream.Unsafer.Write(Quote); } }
public static void ToString(char value, CharStreamPlus jsonStream) { jsonStream.PrepLength(3); var unsafeStream = jsonStream.Unsafer; unsafeStream.Write(Quote); unsafeStream.Write(value); unsafeStream.Write(Quote); }
public static unsafe void ToString(Guid value, CharStreamPlus jsonStream) { var guid = new GuidStruct {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); }
public static unsafe void ToString(byte value, CharStreamPlus jsonStream) { if (value == 0) jsonStream.WriteBase('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); } }
public static unsafe void ToString(sbyte value, CharStreamPlus jsonStream) { if (value == 0) jsonStream.WriteBase('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.WriteBase(chars + 1, 5); } } else { ToString(value, chars); jsonStream.WriteBase(chars + 2, 4); } } }
public static unsafe void ToString(ulong value, CharStreamPlus jsonStream, bool isMaxToString = true) { if (value <= MaxValue || !isMaxToString) { char* chars = stackalloc char[20]; var index = ToString(value, chars); jsonStream.WriteBase(chars + index.Key, index.Value); } else { var unsafeStraem = jsonStream.Unsafer; jsonStream.PrepLength(22); unsafeStraem.Write(Quote); NumberPlus.ToString(value, jsonStream); unsafeStraem.Write(Quote); } }