/// <summary> /// 将 MessagePack 字节缓存反序列化到指定的数据写入器中。 /// </summary> /// <param name="hGCache">MessagePack 字节缓存</param> /// <param name="dataWriter">数据写入器</param> public void DeserializeTo(HGlobalCache <byte> hGCache, IDataWriter dataWriter) { unsafe { DeserializeTo(hGCache.First, hGCache.Count, dataWriter); } }
public void ReaderTest() { var hGCache = new HGlobalCache <char>(); JsonFormatter.SerializeObject(new object[] { 123, "Dogwei", true, null, new { Id = 123 } }, hGCache); var jsonReader = JsonFormatter.CreateJsonReader(hGCache); AreEqual(jsonReader.GetToken(), JsonToken.Array); AreEqual(jsonReader.TryReadBeginArray(), true); AreEqual(jsonReader.TryReadEndArray(), false); AreEqual(jsonReader.GetToken(), JsonToken.Number); AreEqual(jsonReader.ReadInt32(), 123); AreEqual(jsonReader.TryReadEndArray(), false); AreEqual(jsonReader.GetToken(), JsonToken.String); AreEqual(jsonReader.ReadString(), "Dogwei"); AreEqual(jsonReader.TryReadEndArray(), false); AreEqual(jsonReader.GetToken(), JsonToken.Boolean); AreEqual(jsonReader.ReadBoolean(), true); AreEqual(jsonReader.TryReadEndArray(), false); AreEqual(jsonReader.GetToken(), JsonToken.Null); AreEqual(jsonReader.DirectRead(), null); AreEqual(jsonReader.TryReadEndArray(), false); AreEqual(jsonReader.GetToken(), JsonToken.Object); AreEqual(JsonFormatter.SerializeObject(ValueInterface <Dictionary <string, object> > .ReadValue(jsonReader)), "{\"Id\":123}"); AreEqual(jsonReader.TryReadEndArray(), true); AreEqual(jsonReader.GetToken(), JsonToken.End); }
public static async Task <int> BufferAsync(this HGlobalCache <char> hGCache, TextReader textReader) { int offset = 0; Loop: if (offset >= hGCache.Count) { hGCache.Expand(1218); } IntPtr address; unsafe { address = (IntPtr)(hGCache.GetPointer() + offset); } int readCount = await ReadCharsAsync( textReader, address, hGCache.Count - offset); offset += readCount; if (offset == hGCache.Count) { goto Loop; } return(offset); }
public object Deserialize(HGlobalCache <byte> hGCache, Type type) { unsafe { return(Deserialize(hGCache.First, hGCache.Count, type)); } }
public T Deserialize <T>(HGlobalCache <byte> hGCache) { unsafe { return(Deserialize <T>(hGCache.First, hGCache.Count)); } }
public static T DeserializeObject <T>(HGlobalCache <byte> hGCache, MessagePackFormatterOptions options) { unsafe { return(DeserializeObject <T>(hGCache.First, hGCache.Count, options)); } }
public static unsafe int Buffer(this HGlobalCache <char> hGCache, TextReader textReader) { int offset = 0; Loop: if (offset >= hGCache.Count) { hGCache.Expand(1218); } int readCount = ReadChars( textReader, hGCache.GetPointer() + offset, hGCache.Count - offset); offset += readCount; if (offset == hGCache.Count) { goto Loop; } return(offset); }
public static void SerializeObject <T>(T value, HGlobalCache <byte> hGCache) { var messagePackSerializer = new MessagePackSerializer <MessagePackSerializeModes.StandardMode>(hGCache, DefaultMaxDepth); ValueInterface <T> .WriteValue(messagePackSerializer, value); messagePackSerializer.Flush(); }
public MessagePackDeserializer( byte *bytes, int length, HGlobalCache <char> hGlobal, MessagePackForamtter foramtter) : this(bytes, length, hGlobal) { this.foramtter = foramtter; }
public MessagePackSerializer( MessagePackFormatterOptions options, int maxDepth, HGlobalCache <byte> hGlobal, MessagePackForamtter foramtter, Stream stream) : this(options, maxDepth, hGlobal) { MessagePackForamtter = foramtter; Stream = stream; }
public static void SerializeObject <T>(T value, HGlobalCache <byte> hGCache, MessagePackFormatterOptions options) { if ((options & ReferenceSerializerOptions) != 0) { SerializeObject <T, MessagePackSerializeModes.ReferenceMode>(value, hGCache, options); } else { SerializeObject <T, MessagePackSerializeModes.StandardMode>(value, hGCache, options); } }
void Serialize <T, TMode>(T value, HGlobalCache <byte> hGCache, MessagePackFormatterOptions options) where TMode : struct { var messagePackSerializer = new MessagePackSerializer <TMode>(this, hGCache, MaxDepth, options); if (typeof(TMode) == typeof(MessagePackSerializeModes.ReferenceMode)) { messagePackSerializer.InitReferences(); } ValueInterface <T> .WriteValue(messagePackSerializer, value); messagePackSerializer.Flush(); }
public void Serialize <T>(T value, HGlobalCache <byte> hGCache) { var options = Options; if ((options & ReferenceSerializerOptions) != 0) { Serialize <T, MessagePackSerializeModes.ReferenceMode>(value, hGCache, options); } else { Serialize <T, MessagePackSerializeModes.StandardMode>(value, hGCache, options); } }
public MessagePackSerializer( MessagePackFormatterOptions options, int maxDepth, HGlobalCache <byte> hGCache ) { this.Options = options; this.maxDepth = maxDepth; this.HGCache = hGCache; if (typeof(TMode) == typeof(Reference)) { References = new ReferenceCache <int>(); } }
public MessagePackDeserializer( byte *bytes, int length, HGlobalCache <char> hGlobal) { if (bytes == null || length <= 0) { throw new ArgumentNullException(nameof(bytes)); } begin = bytes; end = bytes + length; current = bytes; this.hGlobal = hGlobal; }
public void WriterTest() { var hGCache = new HGlobalCache <char>(); var jsonWriter = JsonFormatter.CreateJsonWriter(hGCache); jsonWriter.WriteBeginObject(); jsonWriter.WritePropertyName("Id"); jsonWriter.WriteInt32(123); jsonWriter.WritePropertyName("Name"); jsonWriter.WriteString("Dogwei"); jsonWriter.WriteEndObject(); jsonWriter.Flush(); var json = hGCache.ToStringEx(); dynamic dyc = JsonFormatter.DeserializeObject <JsonValue>(json); Assert.AreEqual(dyc.Id, 123); Assert.AreEqual(dyc.Name, "Dogwei"); jsonWriter.Clear(); jsonWriter.WriteBeginArray(); jsonWriter.WriteInt32(1); jsonWriter.WriteInt32(2); jsonWriter.WriteInt32(3); jsonWriter.WriteEndArray(); jsonWriter.Flush(); AreEqual(hGCache.ToStringEx(), "[1,2,3]"); }
public T Deserialize <T>(HGlobalCache <byte> hGCache) { throw new NotImplementedException(); }
public static void DeserializeTo <T>(this ITextFormatter textFormatter, HGlobalCache <char> hGCache, T obj) { textFormatter.DeserializeTo(hGCache, RWHelper.CreateWriter(obj)); }
public static IMessagePackWriter CreateMessagePackWriter(HGlobalCache <byte> hGCache) { return(new MessagePackSerializer <MessagePackSerializeModes.StandardMode>(hGCache, DefaultMaxDepth)); }
public static IMessagePackReader CreateMessagePackReader(HGlobalCache <byte> hGCache) { return(CreateMessagePackReader(hGCache.First, hGCache.Count)); }
public void DeserializeTo(HGlobalCache <byte> hGCache, IDataWriter dataWriter) { throw new NotImplementedException(); }
public void Serialize <T>(T value, HGlobalCache <byte> hGCache) { throw new NotImplementedException(); }
public static void DeserializeTo <T>(this IBinaryFormatter binaryFormatter, HGlobalCache <byte> hGCache, T obj) { binaryFormatter.DeserializeTo(hGCache, RWHelper.CreateWriter(obj)); }
public object Deserialize(HGlobalCache <byte> hGCache, Type type) { throw new NotImplementedException(); }