Пример #1
0
        internal MessagePackBinary(int length, MessagePackDeserializer deserializer)
        {
            Length = length;

            ReadBasic(ref length, ref Basic1, deserializer);
            ReadBasic(ref length, ref Basic2, deserializer);
            ReadBasic(ref length, ref Basic3, deserializer);
            ReadBasic(ref length, ref Basic4, deserializer);

            if (length >= 1)
            {
                Extended = new byte[length];

                var index = 0;

                for (; length >= 8; length -= 8, index += 8)
                {
                    Unsafe.As <byte, ulong>(ref Extended[index]) = deserializer.Read8();
                }

                for (; length > 0; --length, ++index)
                {
                    Extended[index] = deserializer.Read();
                }
            }
        }
Пример #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;
            }
        }
Пример #3
0
        private static void ReadBasic(ref int length, ref Basic basic, MessagePackDeserializer deserializer)
        {
            if (length >= 8)
            {
                length -= 8;

                basic.UInt64_0 = deserializer.Read8();

                return;
            }

            if (length >= 4)
            {
                length -= 4;

                basic.UInt32_0 = deserializer.Read4();

                if (length >= 2)
                {
                    length -= 2;

                    basic.UInt16_2 = deserializer.Read2();

                    if (length >= 1)
                    {
                        length -= 1;

                        basic.Byte_6 = deserializer.Read();
                    }
                }

                return;
            }

            if (length >= 2)
            {
                length -= 2;

                basic.UInt16_0 = deserializer.Read2();

                if (length >= 1)
                {
                    length -= 1;

                    basic.Byte_2 = deserializer.Read();
                }

                return;
            }

            if (length >= 1)
            {
                length -= 1;

                basic.Byte_0 = deserializer.Read();
            }
        }
Пример #4
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));
        }
Пример #5
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));
        }
Пример #6
0
        public static unsafe T DeserializeObject <T>(byte *bytes, int length)
        {
            var hGlobal = CacheHelper.RentChars();

            try
            {
                var deserializer = new MessagePackDeserializer(
                    bytes,
                    length,
                    hGlobal);

                return(ValueInterface <T> .ReadValue(deserializer));
            }
            finally
            {
                CacheHelper.Return(hGlobal);
            }
        }
Пример #7
0
        internal MessagePackExtension(int length, byte code, MessagePackDeserializer deserializer)
        {
            Code = code;

            Binary = new MessagePackBinary(length, deserializer);
        }