예제 #1
0
 /// <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);
     }
 }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
 public object Deserialize(HGlobalCache <byte> hGCache, Type type)
 {
     unsafe
     {
         return(Deserialize(hGCache.First, hGCache.Count, type));
     }
 }
예제 #5
0
 public T Deserialize <T>(HGlobalCache <byte> hGCache)
 {
     unsafe
     {
         return(Deserialize <T>(hGCache.First, hGCache.Count));
     }
 }
예제 #6
0
 public static T DeserializeObject <T>(HGlobalCache <byte> hGCache, MessagePackFormatterOptions options)
 {
     unsafe
     {
         return(DeserializeObject <T>(hGCache.First, hGCache.Count, options));
     }
 }
예제 #7
0
        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);
        }
예제 #8
0
        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();
        }
예제 #9
0
 public MessagePackDeserializer(
     byte *bytes,
     int length,
     HGlobalCache <char> hGlobal,
     MessagePackForamtter foramtter) : this(bytes, length, hGlobal)
 {
     this.foramtter = foramtter;
 }
예제 #10
0
 public MessagePackSerializer(
     MessagePackFormatterOptions options,
     int maxDepth,
     HGlobalCache <byte> hGlobal,
     MessagePackForamtter foramtter,
     Stream stream) : this(options, maxDepth, hGlobal)
 {
     MessagePackForamtter = foramtter;
     Stream = stream;
 }
예제 #11
0
 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);
     }
 }
예제 #12
0
        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();
        }
예제 #13
0
        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);
            }
        }
예제 #14
0
        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>();
            }
        }
예제 #15
0
        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;
        }
예제 #16
0
        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]");
        }
예제 #17
0
 public T Deserialize <T>(HGlobalCache <byte> hGCache)
 {
     throw new NotImplementedException();
 }
예제 #18
0
 public static void DeserializeTo <T>(this ITextFormatter textFormatter, HGlobalCache <char> hGCache, T obj)
 {
     textFormatter.DeserializeTo(hGCache, RWHelper.CreateWriter(obj));
 }
예제 #19
0
 public static IMessagePackWriter CreateMessagePackWriter(HGlobalCache <byte> hGCache)
 {
     return(new MessagePackSerializer <MessagePackSerializeModes.StandardMode>(hGCache, DefaultMaxDepth));
 }
예제 #20
0
 public static IMessagePackReader CreateMessagePackReader(HGlobalCache <byte> hGCache)
 {
     return(CreateMessagePackReader(hGCache.First, hGCache.Count));
 }
예제 #21
0
 public void DeserializeTo(HGlobalCache <byte> hGCache, IDataWriter dataWriter)
 {
     throw new NotImplementedException();
 }
예제 #22
0
 public void Serialize <T>(T value, HGlobalCache <byte> hGCache)
 {
     throw new NotImplementedException();
 }
예제 #23
0
 public static void DeserializeTo <T>(this IBinaryFormatter binaryFormatter, HGlobalCache <byte> hGCache, T obj)
 {
     binaryFormatter.DeserializeTo(hGCache, RWHelper.CreateWriter(obj));
 }
예제 #24
0
 public object Deserialize(HGlobalCache <byte> hGCache, Type type)
 {
     throw new NotImplementedException();
 }