Exemplo n.º 1
0
 public static T DeserializeObject <T>(HGlobalCache <byte> hGCache, MessagePackFormatterOptions options)
 {
     unsafe
     {
         return(DeserializeObject <T>(hGCache.First, hGCache.Count, options));
     }
 }
Exemplo n.º 2
0
        void DeserializeTo <TMode>(byte *bytes, int length, IDataWriter dataWriter, MessagePackFormatterOptions options) where TMode : struct
        {
            var deserializer = new MessagePackDeserializer <TMode>(this, bytes, length, MaxDepth, options);

            if (typeof(TMode) == typeof(MessagePackDeserializeModes.ReferenceMode))
            {
                deserializer.InitReferences();
            }

            switch (deserializer.GetToken())
            {
            case MessagePackToken.Map:
                if (dataWriter is IDataWriter <string> objectWriter)
                {
                    deserializer.InternalReadObject(objectWriter);
                }
                else
                {
                    ((IAsDataWriter)dataWriter.As <string>()).InvokeTIn(new MessagePackDeserializer <TMode> .InternalWriteMapInvoker(deserializer, dataWriter));
                }
                break;

            case MessagePackToken.Array:
                deserializer.InternalReadArray(dataWriter.As <int>());
                break;

            default:
                dataWriter.Content = XConvert.Cast(deserializer.DirectRead(), dataWriter.ContentType);
                break;
            }
        }
Exemplo n.º 3
0
 public static object DeserializeObject(byte[] bytes, Type type, MessagePackFormatterOptions options)
 {
     unsafe
     {
         fixed(byte *pBytes = bytes)
         {
             return(DeserializeObject(pBytes, bytes.Length, type, options));
         }
     }
 }
Exemplo n.º 4
0
 public static T DeserializeObject <T>(ReadOnlySpan <byte> bytes, MessagePackFormatterOptions options)
 {
     unsafe
     {
         fixed(byte *pBytes = bytes)
         {
             return(DeserializeObject <T>(pBytes, bytes.Length, options));
         }
     }
 }
Exemplo n.º 5
0
 public static T DeserializeObject <T>(ArraySegment <byte> bytes, MessagePackFormatterOptions options)
 {
     unsafe
     {
         fixed(byte *pBytes = &bytes.Array[bytes.Offset])
         {
             return(DeserializeObject <T>(pBytes, bytes.Count, options));
         }
     }
 }
Exemplo n.º 6
0
 public MessagePackSerializer(
     MessagePackFormatterOptions options,
     int maxDepth,
     HGlobalCache <byte> hGlobal,
     MessagePackForamtter foramtter,
     Stream stream) : this(options, maxDepth, hGlobal)
 {
     MessagePackForamtter = foramtter;
     Stream = stream;
 }
Exemplo n.º 7
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);
     }
 }
Exemplo n.º 8
0
        object Deserialize <TMode>(byte *bytes, int length, Type type, MessagePackFormatterOptions options) where TMode : struct
        {
            var deserializer = new MessagePackDeserializer <TMode>(this, bytes, length, MaxDepth, options);

            if (typeof(TMode) == typeof(MessagePackDeserializeModes.ReferenceMode))
            {
                deserializer.InitReferences();
            }

            return(ValueInterface.GetInterface(type).Read(deserializer));
        }
Exemplo n.º 9
0
 static object DeserializeObject(byte *bytes, int length, Type type, MessagePackFormatterOptions options)
 {
     if ((options & ReferenceDeserializerOptions) != 0)
     {
         return(DeserializeObject <MessagePackDeserializeModes.ReferenceMode>(bytes, length, type, options));
     }
     else
     {
         return(DeserializeObject <MessagePackDeserializeModes.StandardMode>(bytes, length, type, options));
     }
 }
Exemplo n.º 10
0
        static T DeserializeObject <T, TMode>(byte *bytes, int length, MessagePackFormatterOptions options) where TMode : struct
        {
            var deserializer = new MessagePackDeserializer <TMode>(bytes, length, DefaultMaxDepth, options);

            if (typeof(TMode) == typeof(MessagePackDeserializeModes.ReferenceMode))
            {
                deserializer.InitReferences();
            }

            return(ValueInterface <T> .ReadValue(deserializer));
        }
Exemplo n.º 11
0
        SerializeObjectAsync <T>(T value, Stream stream, MessagePackFormatterOptions options)
        {
            var hGBytes = BytesPool.Rent();

            SerializeObject(value, hGBytes, options);

            var bytes = hGBytes.ToArray();

            BytesPool.Return(hGBytes);

            await stream.WriteAsync(bytes, 0, bytes.Length);
        }
Exemplo n.º 12
0
        public static byte[] SerializeObject <T>(T value, MessagePackFormatterOptions options)
        {
            var hGBytes = BytesPool.Rent();

            SerializeObject(value, hGBytes, options);

            var ret = hGBytes.ToArray();

            BytesPool.Return(hGBytes);

            return(ret);
        }
Exemplo n.º 13
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();
        }
Exemplo n.º 14
0
        public int depth;  // 当前结构深度。

        public MessagePackSerializer(
            MessagePackFormatterOptions options,
            int maxDepth,
            HGlobal hGlobal,
            MessagePackForamtter foramtter = null,
            Stream stream = null)
        {
            this.options   = options;
            this.maxDepth  = maxDepth;
            this.hGlobal   = hGlobal;
            this.foramtter = foramtter;
            this.stream    = stream;
        }
Exemplo n.º 15
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>();
            }
        }
Exemplo n.º 16
0
        public static void SerializeObject <T>(T value, Stream stream, MessagePackFormatterOptions options)
        {
            var hGBytes = BytesPool.Rent();

            if ((options & ReferenceSerializerOptions) != 0)
            {
                SerializeObject <T, MessagePackSerializeModes.ReferenceMode>(value, hGBytes, options);
            }
            else
            {
                SerializeObject <T, MessagePackSerializeModes.StandardMode>(value, hGBytes, options);
            }

            hGBytes.WriteTo(stream);

            BytesPool.Return(hGBytes);
        }
Exemplo n.º 17
0
 /// <summary>
 /// 初始化具有指定配置项的 MessagePack 格式化器。
 /// </summary>
 /// <param name="options">指定配置项</param>
 public MessagePackFormatter(MessagePackFormatterOptions options = MessagePackFormatterOptions.Default)
 {
     Options = options;
 }
Exemplo n.º 18
0
 DeserializeObjectAsync(Stream stream, Type type, MessagePackFormatterOptions options)
 {
     return(DeserializeObject(await stream.ReadToEndAsync(), type, options));
 }
Exemplo n.º 19
0
 DeserializeObjectAsync <T>(Stream stream, MessagePackFormatterOptions options)
 {
     return(DeserializeObject <T>(await stream.ReadToEndAsync(), options));
 }
Exemplo n.º 20
0
 public static T DeserializeObject <T>(Stream stream, MessagePackFormatterOptions options)
 {
     return(DeserializeObject <T>(stream.ReadToEnd(), options));
 }
Exemplo n.º 21
0
 public static object DeserializeObject(Stream stream, Type type, MessagePackFormatterOptions options)
 {
     return(DeserializeObject(stream.ReadToEnd(), type, options));
 }