public BaseJsonSerializer() { offset = 0; hGlobal = HGlobalCache <char> .OccupancyInstance(); Expand(255); }
public static void SerializeObject <T>(T value, HGlobalCache <char> hGCache) { var jsonSerializer = new JsonSerializer <JsonSerializeModes.SimpleMode>(hGCache, DefaultMaxDepth); ValueInterface <T> .WriteValue(jsonSerializer, value); jsonSerializer.Flush(); }
public BaseJsonSerializer() { offset = 0; hGlobal = HGlobalCache.ThreadInstance; Expand(255); }
public object Deserialize(TextReader textReader, Type type) { using (var hGCache = HGlobalCache <char> .OccupancyInstance()) { var length = hGCache.Buffer(textReader); return(Deserialize(hGCache.GetPointer(), length, type)); } }
public static object DeserializeObject(TextReader textReader, Type type, JsonFormatterOptions options) { using (var hGCache = HGlobalCache <char> .OccupancyInstance()) { var length = hGCache.Buffer(textReader); return(DeserializeObject(hGCache.GetPointer(), length, type, options)); } }
public static T DeserializeObject <T>(TextReader textReader) { using (var hGCache = HGlobalCache <char> .OccupancyInstance()) { var length = hGCache.Buffer(textReader); return(DeserializeObject <T>(hGCache.GetPointer(), length)); } }
public void Serialize <T>(T value, HGlobalCache <char> hGCache) { var options = Options; if ((options & ReferenceOptions) != 0) { var jsonSerializer = new JsonSerializer <JsonSerializeModes.ReferenceMode>(options, hGCache, MaxDepth) { jsonFormatter = this, References = new JsonReferenceWriter() }; if ((options & JsonFormatterOptions.Indented) != 0) { jsonSerializer.IndentedChars = IndentedChars; jsonSerializer.LineBreakChars = LineBreakChars; jsonSerializer.MiddleChars = MiddleChars; } ValueInterface <T> .WriteValue(jsonSerializer, value); jsonSerializer.Flush(); } else if ((options & ComplexOptions) != 0) { var jsonSerializer = new JsonSerializer <JsonSerializeModes.ComplexMode>(options, hGCache, MaxDepth) { jsonFormatter = this }; if ((options & JsonFormatterOptions.Indented) != 0) { jsonSerializer.IndentedChars = IndentedChars; jsonSerializer.LineBreakChars = LineBreakChars; jsonSerializer.MiddleChars = MiddleChars; } ValueInterface <T> .WriteValue(jsonSerializer, value); jsonSerializer.Flush(); } else { var jsonSerializer = new JsonSerializer <JsonSerializeModes.SimpleMode>(options, hGCache, MaxDepth) { jsonFormatter = this }; ValueInterface <T> .WriteValue(jsonSerializer, value); jsonSerializer.Flush(); } }
public static async Task <T> DeserializeObjectAsync <T>(TextReader textReader) { using (var hGCache = HGlobalCache <char> .OccupancyInstance()) { var length = await hGCache.BufferAsync(textReader); unsafe { return(DeserializeObject <T>(hGCache.GetPointer(), length)); } } }
public async Task <object> DeserializeAsync(TextReader textReader, Type type) { using (var hGCache = HGlobalCache <char> .OccupancyInstance()) { var length = await hGCache.BufferAsync(textReader); unsafe { return(Deserialize(hGCache.GetPointer(), length, type)); } } }
public static async Task <object> DeserializeObjectAsync(TextReader textReader, Type type, JsonFormatterOptions options) { using (var hGCache = HGlobalCache <char> .OccupancyInstance()) { var length = await hGCache.BufferAsync(textReader); unsafe { return(DeserializeObject(hGCache.GetPointer(), length, type, options)); } } }
public static void SerializeObject <T>(T value, HGlobalCache <char> hGCache, JsonFormatterOptions options) { if ((options & ReferenceOptions) != 0) { var jsonSerializer = new JsonSerializer <JsonSerializeModes.ReferenceMode>(options, hGCache, DefaultMaxDepth) { References = new JsonReferenceWriter() }; if ((options & JsonFormatterOptions.Indented) != 0) { jsonSerializer.IndentedChars = DefaultIndentedChars; jsonSerializer.LineBreakChars = DefaultLineCharsBreak; jsonSerializer.MiddleChars = DefaultMiddleChars; } ValueInterface <T> .WriteValue(jsonSerializer, value); jsonSerializer.Flush(); } else if ((options & ComplexOptions) != 0) { var jsonSerializer = new JsonSerializer <JsonSerializeModes.ComplexMode>(options, hGCache, DefaultMaxDepth); if ((options & JsonFormatterOptions.Indented) != 0) { jsonSerializer.IndentedChars = DefaultIndentedChars; jsonSerializer.LineBreakChars = DefaultLineCharsBreak; jsonSerializer.MiddleChars = DefaultMiddleChars; } ValueInterface <T> .WriteValue(jsonSerializer, value); jsonSerializer.Flush(); } else { var jsonSerializer = new JsonSerializer <DefaultSerializeMode>(options, hGCache, DefaultMaxDepth); ValueInterface <T> .WriteValue(jsonSerializer, value); jsonSerializer.Flush(); } }
/// <summary> /// 将 Stream 的内容缓存到 HGlobalCache 中。 /// </summary> /// <param name="hGCache">HGlobalCache</param> /// <param name="stream">Stream</param> /// <param name="encoding">编码</param> /// <returns>返回缓冲的长度</returns> public static void ReadFrom(this HGlobalCache <char> hGCache, Stream stream, Encoding encoding) { var hGBytes = BytesPool.Rent(); hGBytes.ReadFrom(stream); var maxCharsCount = encoding.GetMaxCharCount(hGBytes.Count); if (maxCharsCount >= hGCache.Capacity) { hGCache.Expand(maxCharsCount); } hGCache.Count = encoding.GetChars( hGBytes.GetPointer(), hGBytes.Count, hGCache.GetPointer(), hGCache.Capacity); BytesPool.Return(hGBytes); }
/// <summary> /// 将 HGlobalCache 中的内容写入到流中。 /// </summary> /// <param name="hGCache">HGlobalCache</param> /// <param name="stream">流</param> /// <param name="encoding">编码</param> public static void WriteTo(this HGlobalCache <char> hGCache, Stream stream, Encoding encoding) { var hGBytes = BytesPool.Rent(); var maxBytesCount = encoding.GetMaxByteCount(hGCache.Count); if (maxBytesCount > hGBytes.Capacity) { hGBytes.Expand(maxBytesCount - hGBytes.Capacity); } hGBytes.Count = encoding.GetBytes( hGCache.GetPointer(), hGCache.Count, hGBytes.GetPointer(), hGBytes.Capacity); hGBytes.WriteTo(stream); BytesPool.Return(hGBytes); }
static void SerializeObject <T, TMode>(T value, HGlobalCache <char> hGCache, TextWriter textWriter, JsonFormatterOptions options) where TMode : struct { var jsonSerializer = new JsonSerializer <TMode>(hGCache, DefaultMaxDepth, textWriter, options); if (typeof(TMode) == typeof(JsonSerializeModes.ReferenceMode)) { jsonSerializer.References = new JsonReferenceWriter(); } if (typeof(TMode) == typeof(JsonSerializeModes.ReferenceMode) || typeof(TMode) == typeof(JsonSerializeModes.ComplexMode)) { if ((options & JsonFormatterOptions.Indented) != 0) { jsonSerializer.IndentedChars = DefaultIndentedChars; jsonSerializer.LineBreakChars = DefaultLineCharsBreak; jsonSerializer.MiddleChars = DefaultMiddleChars; } } ValueInterface <T> .WriteValue(jsonSerializer, value); jsonSerializer.Flush(); }
/// <summary> /// 异步将 Stream 的内容缓存到 HGlobalCache 中。 /// </summary> /// <param name="hGCache">HGlobalCache</param> /// <param name="stream">Stream</param> /// <param name="encoding">编码</param> /// <returns>返回缓冲的长度</returns> public static async Task ReadFromAsync(this HGlobalCache <char> hGCache, Stream stream, Encoding encoding) { var hGBytes = BytesPool.Rent(); await hGBytes.ReadFromAsync(stream); var maxCharsCount = encoding.GetMaxCharCount(hGBytes.Count); if (maxCharsCount > hGCache.Capacity) { hGCache.Expand(maxCharsCount - hGCache.Capacity); } unsafe { hGCache.Count = encoding.GetChars( hGBytes.GetPointer(), hGBytes.Count, hGCache.GetPointer(), hGCache.Capacity); } BytesPool.Return(hGBytes); }
void Serialize <T, TMode>(T value, HGlobalCache <char> hGCache, JsonFormatterOptions options) where TMode : struct { var jsonSerializer = new JsonSerializer <TMode>(this, hGCache, MaxDepth, options); if (typeof(TMode) == typeof(JsonSerializeModes.ReferenceMode)) { jsonSerializer.References = new JsonReferenceWriter(); } if (typeof(TMode) == typeof(JsonSerializeModes.ReferenceMode) || typeof(TMode) == typeof(JsonSerializeModes.ComplexMode)) { if ((options & JsonFormatterOptions.Indented) != 0) { jsonSerializer.IndentedChars = IndentedChars; jsonSerializer.LineBreakChars = LineBreakChars; jsonSerializer.MiddleChars = MiddleChars; } } ValueInterface <T> .WriteValue(jsonSerializer, value); jsonSerializer.Flush(); }
public JsonSerializer(HGlobalCache <char> hGCache, int maxDepth, TextWriter textWriter) : this(hGCache, maxDepth) { TextWriter = textWriter; }
public static T DeserializeObject <T>(HGlobalCache <char> hGCache, JsonFormatterOptions options) { return(DeserializeObject <T>(hGCache.GetPointer(), hGCache.Count, options)); }
public static object DeserializeObject(HGlobalCache <char> hGCache, Type type, JsonFormatterOptions options) { return(DeserializeObject(hGCache.GetPointer(), hGCache.Count, type, options)); }
public static IJsonReader CreateJsonReader(HGlobalCache <char> hGCache) { return(CreateJsonReader(hGCache.GetPointer(), hGCache.Count)); }
/// <summary> /// 将 JSON 字符串反序列化到指定的数据写入器中。 /// </summary> /// <param name="hGCache">JSON 字符串缓存</param> /// <param name="dataWriter">数据写入器</param> public void DeserializeTo(HGlobalCache <char> hGCache, IDataWriter dataWriter) { DeserializeTo(hGCache.GetPointer(), hGCache.Count, dataWriter); }
public JsonSerializer(HGlobalCache <char> hGCache, int maxDepth) { HGCache = hGCache; MaxDepth = maxDepth; }
public object Deserialize(HGlobalCache <char> hGCache, Type type) { return(Deserialize(hGCache.GetPointer(), hGCache.Count, type)); }
public T Deserialize <T>(HGlobalCache <char> hGCache) { return(Deserialize <T>(hGCache.GetPointer(), hGCache.Count)); }
public JsonSerializer(HGlobalCache <char> hGCache, int maxDepth, TextWriter textWriter, JsonFormatterOptions options) : this(hGCache, maxDepth) { TextWriter = textWriter; Options = options; }
public JsonSerializer(JsonFormatter jsonFormatter, HGlobalCache <char> hGCache, int maxDepth, TextWriter textWriter, JsonFormatterOptions options) : this(jsonFormatter, hGCache, maxDepth, options) { TextWriter = textWriter; }
public JsonSerializer(JsonFormatter jsonFormatter, HGlobalCache <char> hGCache, int maxDepth, JsonFormatterOptions options) : this(hGCache, maxDepth) { JsonFormatter = jsonFormatter; Options = options; }