Exemple #1
0
        public global::TestData2.A Deserialize(byte[] bytes, int offset, global::MessagePack.IFormatterResolver formatterResolver, out int readSize)
        {
            if (global::MessagePack.MessagePackBinary.IsNil(bytes, offset))
            {
                readSize = 1;
                return(null);
            }

            var startOffset = offset;
            var length      = global::MessagePack.MessagePackBinary.ReadMapHeader(bytes, offset, out readSize);

            offset += readSize;

            var __a__  = default(int);
            var __bs__ = default(global::System.Collections.Generic.List <global::TestData2.B>);
            var __c__  = default(global::TestData2.C);

            for (int i = 0; i < length; i++)
            {
                var stringKey = global::MessagePack.MessagePackBinary.ReadStringSegment(bytes, offset, out readSize);
                offset += readSize;
                int key;
                if (!____keyMapping.TryGetValueSafe(stringKey, out key))
                {
                    readSize = global::MessagePack.MessagePackBinary.ReadNextBlock(bytes, offset);
                    goto NEXT_LOOP;
                }

                switch (key)
                {
                case 0:
                    __a__ = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                    break;

                case 1:
                    __bs__ = formatterResolver.GetFormatterWithVerify <global::System.Collections.Generic.List <global::TestData2.B> >().Deserialize(bytes, offset, formatterResolver, out readSize);
                    break;

                case 2:
                    __c__ = formatterResolver.GetFormatterWithVerify <global::TestData2.C>().Deserialize(bytes, offset, formatterResolver, out readSize);
                    break;

                default:
                    readSize = global::MessagePack.MessagePackBinary.ReadNextBlock(bytes, offset);
                    break;
                }

NEXT_LOOP:
                offset += readSize;
            }

            readSize = offset - startOffset;

            var ____result = new global::TestData2.A();

            ____result.a  = __a__;
            ____result.bs = __bs__;
            ____result.c  = __c__;
            return(____result);
        }
Exemple #2
0
        public Bgra32Image Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
        {
            if (MessagePackBinary.IsNil(bytes, offset))
            {
                readSize = 1;
                return(null);
            }

            var startOffset = offset;

            var arrayCount = MessagePackBinary.ReadArrayHeaderRaw(bytes, offset, out var rs);

            offset += rs;

            if (arrayCount != 3)
            {
                throw new InvalidDataException();
            }

            var width = MessagePackBinary.ReadInt32(bytes, offset, out rs);

            offset += rs;

            var height = MessagePackBinary.ReadInt32(bytes, offset, out rs);

            offset += rs;

            var data = MessagePackBinary.ReadBytesSegment(bytes, offset, out rs);

            offset += rs;

            readSize = offset - startOffset;
            return(new Bgra32ImageFromMessagePack(width, height, data));
        }
        public static byte[] UnpackDataIfRequired(byte[] bytes)
        {
            if (MessagePackBinary.GetMessagePackType(bytes, 0) == MessagePackType.Extension)
            {
                var header = MessagePackBinary.ReadExtensionFormatHeader(bytes, 0, out var readSize);
                if (header.TypeCode == ExtensionTypeCode)
                {
                    // decode lz4
                    int offset = readSize;
                    int length = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                    offset += readSize;

                    byte[] buffer = GetLz4Buffer();
                    if (buffer.Length < length)
                    {
                        buffer = new byte[length];
                    }

                    // LZ4 Decode
                    int len = bytes.Length - offset;
                    LZ4Codec.Decode(bytes, offset, len, buffer, 0, length);

                    return(buffer);
                }
            }

            return(bytes);
        }
Exemple #4
0
    public int GetInt()
    {
        int value = MessagePackBinary.ReadInt32(_bytes, _offset, out int length);

        _offset += length;
        return(value);
    }
Exemple #5
0
        public IHogeMoge Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
        {
            // TODO:array header...

            int keySize;
            int valueSize;
            var key = MessagePackBinary.ReadInt32(bytes, offset, out keySize);

            switch (key)
            {
            case 0:
            {
                var result = formatterResolver.GetFormatterWithVerify <HogeMoge1>().Deserialize(bytes, offset + keySize, formatterResolver, out valueSize);
                readSize = keySize + valueSize;
                return((IHogeMoge)result);
            }

            case 1:
            {
                var result = formatterResolver.GetFormatterWithVerify <HogeMoge2>().Deserialize(bytes, offset + keySize, formatterResolver, out valueSize);
                readSize = keySize + valueSize;
                return((IHogeMoge)result);
            }

            default:
            {
                throw new NotImplementedException();
            }
            }
        }
        private SwimMember DeserializeMember(byte[] bytes, int offset, out int readSize)
        {
            readSize = 0;

            var host = DeserializeHost(bytes, offset + readSize, out var r);

            readSize += r;

            var metaCount = MessagePackBinary.ReadMapHeader(bytes, offset + readSize, out r);

            readSize += r;
            var meta = new Dictionary <string, string>();

            for (var i = 0; i < metaCount; i++)
            {
                var key = MessagePackBinary.ReadString(bytes, offset + readSize, out r);
                readSize += r;
                var value = MessagePackBinary.ReadString(bytes, offset + readSize, out r);
                readSize += r;

                meta.Add(key, value);
            }

            var state = (SwimMemberState)MessagePackBinary.ReadByte(bytes, offset + readSize, out r);

            readSize += r;
            var incarnation = MessagePackBinary.ReadInt32(bytes, offset + readSize, out r);

            readSize += r;

            return(new SwimMember(host, new SwimMeta(meta), state, incarnation));
        }
Exemple #7
0
        public BufferedMatrix(Stream source, QuantizationType quantization, int cacheSize) : base()
        {
            Source      = source;
            Rows        = MessagePackBinary.ReadInt32(source);
            Columns     = MessagePackBinary.ReadInt32(source);
            BeginOfData = source.Position;

            var tempArray = MessagePackBinary.ReadBytes(source);

            RowSize = source.Position - BeginOfData;

            Quantization   = quantization;
            DisposingToken = new CancellationTokenSource();

            CacheThread = new Thread(() =>
            {
                while (!DisposingToken.Token.IsCancellationRequested)
                {
                    if (Interlocked.Read(ref CacheCount) > cacheSize)
                    {
                        CacheLock.EnterWriteLock();
                        Cache.Clear();
                        CacheCount = 0;
                        CacheLock.ExitWriteLock();
                    }
                    Thread.Sleep(1000);
                }
            });
            CacheThread.IsBackground = true; //Won't block when terminating the process
            CacheThread.Start();
        }
        public global::SkillParameter Deserialize(byte[] bytes, int offset, global::MessagePack.IFormatterResolver formatterResolver, out int readSize)
        {
            if (global::MessagePack.MessagePackBinary.IsNil(bytes, offset))
            {
                readSize = 1;
                return(null);
            }

            var startOffset = offset;
            var length      = global::MessagePack.MessagePackBinary.ReadMapHeader(bytes, offset, out readSize);

            offset += readSize;

            var __SkillID__ = default(int);
            var __SkillLv__ = default(int);
            var __Damage__  = default(int);

            for (int i = 0; i < length; i++)
            {
                var stringKey = global::MessagePack.MessagePackBinary.ReadStringSegment(bytes, offset, out readSize);
                offset += readSize;
                int key;
                if (!____keyMapping.TryGetValueSafe(stringKey, out key))
                {
                    readSize = global::MessagePack.MessagePackBinary.ReadNextBlock(bytes, offset);
                    goto NEXT_LOOP;
                }

                switch (key)
                {
                case 0:
                    __SkillID__ = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                    break;

                case 1:
                    __SkillLv__ = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                    break;

                case 2:
                    __Damage__ = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                    break;

                default:
                    readSize = global::MessagePack.MessagePackBinary.ReadNextBlock(bytes, offset);
                    break;
                }

NEXT_LOOP:
                offset += readSize;
            }

            readSize = offset - startOffset;

            var ____result = new global::SkillParameter();

            ____result.SkillID = __SkillID__;
            ____result.SkillLv = __SkillLv__;
            ____result.Damage  = __Damage__;
            return(____result);
        }
        public void Standard()
        {
            var o = new SimpleIntKeyData()
            {
                Prop1 = 100,
                Prop2 = ByteEnum.C,
                Prop3 = "abcde",
                Prop4 = new SimlpeStringKeyData
                {
                    Prop1 = 99999,
                    Prop2 = ByteEnum.E,
                    Prop3 = 3
                },
                Prop5 = new SimpleStructIntKeyData
                {
                    X            = 100,
                    Y            = 300,
                    BytesSpecial = new byte[] { 9, 99, 122 }
                },
                Prop6 = new SimpleStructStringKeyData
                {
                    X = 9999,
                    Y = new[] { 1, 10, 100 }
                },
                BytesSpecial = new byte[] { 1, 4, 6 }
            };


            var bytes = MessagePackSerializer.Serialize(o);
            var ms    = new MemoryStream(bytes);

            MessagePackBinary.ReadArrayHeader(ms).Is(7);
            MessagePackBinary.ReadInt32(ms).Is(100);
            MessagePackBinary.ReadByte(ms).Is((byte)ByteEnum.C);
            MessagePackBinary.ReadString(ms).Is("abcde");

            MessagePackBinary.ReadMapHeader(ms).Is(3);
            MessagePackBinary.ReadString(ms).Is("Prop1");
            MessagePackBinary.ReadInt32(ms).Is(99999);
            MessagePackBinary.ReadString(ms).Is("Prop2");
            MessagePackBinary.ReadByte(ms).Is((byte)ByteEnum.E);
            MessagePackBinary.ReadString(ms).Is("Prop3");
            MessagePackBinary.ReadInt32(ms).Is(3);

            MessagePackBinary.ReadArrayHeader(ms).Is(3);
            MessagePackBinary.ReadInt32(ms).Is(100);
            MessagePackBinary.ReadInt32(ms).Is(300);
            MessagePackBinary.ReadBytes(ms).Is(new byte[] { 9, 99, 122 });

            MessagePackBinary.ReadMapHeader(ms).Is(2);
            MessagePackBinary.ReadString(ms).Is("key-X");
            MessagePackBinary.ReadInt32(ms).Is(9999);
            MessagePackBinary.ReadString(ms).Is("key-Y");
            MessagePackBinary.ReadArrayHeader(ms).Is(3);
            MessagePackBinary.ReadInt32(ms).Is(1);
            MessagePackBinary.ReadInt32(ms).Is(10);
            MessagePackBinary.ReadInt32(ms).Is(100);

            MessagePackBinary.ReadBytes(ms).Is(new byte[] { 1, 4, 6 });
        }
        public decimal Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
        {
            //return decimal.Parse(MessagePackBinary.ReadString(bytes, offset, out readSize), CultureInfo.InvariantCulture);
            var startOffset = offset;
            var count       = MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize);

            offset += readSize;

            if (count != 4)
            {
                ThrowHelper.ThrowInvalidOperationException_Decimal_Format();
            }

            var lo = MessagePackBinary.ReadInt32(bytes, offset, out readSize);

            offset += readSize;
            var mid = MessagePackBinary.ReadInt32(bytes, offset, out readSize);

            offset += readSize;
            var hi = MessagePackBinary.ReadInt32(bytes, offset, out readSize);

            offset += readSize;
            var flags = MessagePackBinary.ReadInt32(bytes, offset, out readSize);

            offset += readSize;

            readSize = offset - startOffset;

            return(new decimal(new int[] { lo, mid, hi, flags }));
        }
Exemple #11
0
        public Int32[] Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
        {
            if (MessagePackBinary.IsNil(bytes, offset))
            {
                readSize = 1;
                return(null);
            }
            else
            {
                var startOffset = offset;

                var len = MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize);
                offset += readSize;
                var array = new Int32[len];
                using (MessagePackSecurity.DepthStep())
                {
                    for (int i = 0; i < array.Length; i++)
                    {
                        array[i] = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                        offset  += readSize;
                    }
                }

                readSize = offset - startOffset;
                return(array);
            }
        }
Exemple #12
0
        public ReactiveProperty <T> Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
        {
            if (MessagePackBinary.IsNil(bytes, offset))
            {
                readSize = 1;
                return(null);
            }
            else
            {
                var startOffset = offset;

                var length = MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize);
                offset += readSize;
                if (length != 3)
                {
                    throw new InvalidOperationException("Invalid ReactiveProperty data.");
                }

                var mode = (ReactivePropertyMode)MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                offset += readSize;

                var schedulerId = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                offset += readSize;

                var scheduler = ReactivePropertySchedulerMapper.GetScheduler(schedulerId);

                var v = formatterResolver.GetFormatterWithVerify <T>().Deserialize(bytes, offset, formatterResolver, out readSize);
                offset += readSize;

                readSize = offset - startOffset;

                return(new ReactiveProperty <T>(scheduler, v, mode));
            }
        }
Exemple #13
0
        public T Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
        {
            if (MessagePackBinary.IsNil(bytes, offset))
            {
                readSize = 1;
                return(null);
            }

            var startOffset   = offset;
            var elementsCount = MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize);

            offset += readSize;

            object instance;

            if (MessagePackBinary.IsNil(bytes, offset))
            {
                // reference:
                MessagePackBinary.ReadNil(bytes, offset, out readSize);
                offset += readSize;
                var reference = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                offset += readSize;

                instance = Serializer.Instance.State.GetInstance(reference);
            }
            else
            {
                // full deserialization:
                var meta = DarkMeta <T> .Value;
                if (!meta.Flags.IsStatic())
                {
                    var typeIndex = (TypeIndex)MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                    offset += readSize;
                    if (typeIndex != meta.TypeIndex)
                    {
                        meta = DarkMeta.Get(typeIndex);
                        if (meta == null)
                        {
                            Logger.Instance.Warning(String.Format("Can't find typeIndex {0}", typeIndex));
                            for (int i = 0; i < elementsCount - 1; i++)
                            {
                                offset += MessagePackBinary.ReadNextBlock(bytes, offset);
                            }
                            readSize = offset - startOffset;
                            return(null);
                        }
                    }
                }

                instance = DeserializeBody(meta.Type, elementsCount - 1, bytes, offset, formatterResolver, out readSize);

                offset += readSize;
                meta.OnDeserialized(instance);
            }

            readSize = offset - startOffset;

            return(instance as T);
        }
Exemple #14
0
        /// <inheritdoc />
        public Recording Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
        {
            if (MessagePackBinary.IsNil(bytes, offset))
            {
                readSize = 1;
                return(null);
            }

            int startOffset = offset;

            int count = MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize);

            offset += readSize;
            // NOTE: We can use this to distinguish between future versions of a Recording.
            if (count != 6)
            {
                throw new InvalidOperationException("Request format invalid.");
            }

            string hash = MessagePackBinary.ReadString(bytes, offset, out readSize);

            offset += readSize;

            string keyGeneratorName = MessagePackBinary.ReadString(bytes, offset, out readSize);

            offset += readSize;

            DateTime recordedUtc = MessagePackBinary.ReadDateTime(bytes, offset, out readSize);

            offset += readSize;

            int durationMs = MessagePackBinary.ReadInt32(bytes, offset, out readSize);

            offset += readSize;

            byte[] responseData = MessagePackBinary.ReadBytes(bytes, offset, out readSize);
            offset += readSize;

            byte[] requestData;
            if (MessagePackBinary.IsNil(bytes, offset))
            {
                requestData = null;
                offset++;
            }
            else
            {
                requestData = MessagePackBinary.ReadBytes(bytes, offset, out readSize);
                offset     += readSize;
            }
            readSize = offset - startOffset;

            return(new Recording(
                       hash,
                       keyGeneratorName,
                       recordedUtc,
                       durationMs,
                       responseData,
                       requestData));
        }
Exemple #15
0
        public static int ReadInt32(ref ReadOnlyMemory <byte> data)
        {
            var arr = GetArray(data);
            var val = MessagePackBinary.ReadInt32(arr.Array, arr.Offset, out var readSize);

            data = data.Slice(readSize);
            return(val);
        }
Exemple #16
0
        public int ReadInt32()
        {
            int value = MessagePackBinary.ReadInt32(Buffer, Position, out int readSize);

            Position += readSize;

            return(value);
        }
        public global::MasterMemory.Tests.Sample Deserialize(byte[] bytes, int offset, global::MessagePack.IFormatterResolver formatterResolver, out int readSize)
        {
            if (global::MessagePack.MessagePackBinary.IsNil(bytes, offset))
            {
                readSize = 1;
                return(null);
            }

            var startOffset = offset;
            var length      = global::MessagePack.MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize);

            offset += readSize;

            var __Id__        = default(int);
            var __Age__       = default(int);
            var __FirstName__ = default(string);
            var __LastName__  = default(string);

            for (int i = 0; i < length; i++)
            {
                var key = i;

                switch (key)
                {
                case 0:
                    __Id__ = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                    break;

                case 1:
                    __Age__ = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                    break;

                case 2:
                    __FirstName__ = MessagePackBinary.ReadString(bytes, offset, out readSize);
                    break;

                case 3:
                    __LastName__ = MessagePackBinary.ReadString(bytes, offset, out readSize);
                    break;

                default:
                    readSize = global::MessagePack.MessagePackBinary.ReadNext(bytes, offset);
                    break;
                }
                offset += readSize;
            }

            readSize = offset - startOffset;

            var ____result = new global::MasterMemory.Tests.Sample();

            ____result.Id        = __Id__;
            ____result.Age       = __Age__;
            ____result.FirstName = __FirstName__;
            ____result.LastName  = __LastName__;
            return(____result);
        }
Exemple #18
0
        FieldList IMessagePackFormatter <FieldList> .Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
        {
            if (MessagePackBinary.IsNil(bytes, offset))
            {
                readSize = 1;
                return(null);
            }

            var startOffset   = offset;
            var elementsCount = MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize) / 3;

            offset += readSize;

            var list = new FieldList(elementsCount);

            var state = Serializer.Instance.State;

            if (state.Settings.Flags.HasFlag(SerializationFlags.KeepOriginalBytes))
            {
                list.OriginalBytes = new List <FieldBytes>();
            }

            var previousOffset = state.LocalOffset;

            for (int i = 0; i < elementsCount; i++)
            {
                state.StartLocalGroup();

                var typeId = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                offset += readSize;

                var memberId = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                offset += readSize;

                if (typeId >= 0)
                {
                    // normal
                    var fieldKey = new FieldKey((TypeIndex)typeId, memberId);
                    list[fieldKey] = FieldMeta.Get(fieldKey).Deserialize(bytes, offset, formatterResolver, out readSize);
                    list.OriginalBytes?.Add(new FieldBytes(fieldKey, offset, readSize));
                    offset += readSize;
                }
                else
                {
                    // ValueProducer
                    var fieldKey = new FieldKey((TypeIndex)(-typeId), memberId);
                    list[fieldKey] = formatterResolver.GetFormatter <ValueProducer>().Deserialize(bytes, offset, formatterResolver, out readSize);
                    list.OriginalBytes?.Add(new FieldBytes(fieldKey, offset, readSize));
                    offset += readSize;
                }
            }
            state.RestoreLocalGroup(previousOffset);

            readSize = offset - startOffset;

            return(list);
        }
Exemple #19
0
        public LocalDate Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
        {
            var v     = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
            var year  = unchecked (((v & YearMask) >> CalendarDayMonthBits) + 1);
            var month = unchecked (((v & MonthMask) >> CalendarDayBits) + 1);
            var day   = unchecked (((v & DayMask) >> CalendarBits) + 1);

            return(new LocalDate(year, month, day));
        }
        public int?Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
        {
            if (MessagePackBinary.IsNil(bytes, offset))
            {
                readSize = 1;
                return(null);
            }

            return(MessagePackBinary.ReadInt32(bytes, offset, out readSize));
        }
Exemple #21
0
        public T[,] Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
        {
            if (MessagePackBinary.IsNil(bytes, offset))
            {
                readSize = 1;
                return(null);
            }
            else
            {
                var startOffset = offset;
                var formatter   = formatterResolver.GetFormatterWithVerify <T>();

                var len = MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize);
                offset += readSize;
                if (len != ArrayLength)
                {
                    throw new InvalidOperationException("Invalid T[,] format");
                }

                var iLength = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                offset += readSize;

                var jLength = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                offset += readSize;

                var maxLen = MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize);
                offset += readSize;

                var array = new T[iLength, jLength];

                var i = 0;
                var j = -1;
                using (MessagePackSecurity.DepthStep())
                {
                    for (int loop = 0; loop < maxLen; loop++)
                    {
                        if (j < jLength - 1)
                        {
                            j++;
                        }
                        else
                        {
                            j = 0;
                            i++;
                        }

                        array[i, j] = formatter.Deserialize(bytes, offset, formatterResolver, out readSize);
                        offset     += readSize;
                    }
                }

                readSize = offset - startOffset;
                return(array);
            }
        }
Exemple #22
0
    public Color Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
    {
        var startOffset = offset;
        var R           = MessagePackBinary.ReadInt32(bytes, offset, out readSize); offset += readSize;
        var G           = MessagePackBinary.ReadInt32(bytes, offset, out readSize); offset += readSize;
        var B           = MessagePackBinary.ReadInt32(bytes, offset, out readSize); offset += readSize;
        var A           = MessagePackBinary.ReadInt32(bytes, offset, out readSize); offset += readSize;

        readSize = offset - startOffset;
        return(new Color(R, G, B, A));
    }
Exemple #23
0
    public Point Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
    {
        var startOffset = offset;
        var x           = MessagePackBinary.ReadInt32(bytes, offset, out readSize);

        offset += readSize;
        var y = MessagePackBinary.ReadInt32(bytes, offset, out readSize);

        offset  += readSize;
        readSize = offset - startOffset;
        return(new Point(x, y));
    }
 public Int32?Deserialize(byte[] bytes, int offset, out int readSize)
 {
     if (MessagePackBinary.IsNil(bytes, offset))
     {
         readSize = 1;
         return(null);
     }
     else
     {
         return(MessagePackBinary.ReadInt32(bytes, offset, out readSize));
     }
 }
            public Target Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
            {
                int start = offset;
                var value = new Target();

                value.BoolValue = MessagePackBinary.ReadBoolean(bytes, offset, out readSize);
                offset         += readSize;
                value.IntValue  = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                offset         += readSize;

                readSize = offset - start;
                return(value);
            }
        public unsafe T[] Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
        {
            if (MessagePackBinary.IsNil(bytes, offset))
            {
                readSize = 1;
                return(null);
            }

            var startOffset = offset;
            var header      = MessagePackBinary.ReadExtensionFormatHeader(bytes, offset, out readSize);

            offset += readSize;

            if (header.TypeCode != TypeCode)
            {
                throw new InvalidOperationException("Invalid typeCode.");
            }

            var byteLength = MessagePackBinary.ReadInt32(bytes, offset, out readSize);

            offset += readSize;

            var isLittleEndian = MessagePackBinary.ReadBoolean(bytes, offset, out readSize);

            offset += readSize;

            if (isLittleEndian != BitConverter.IsLittleEndian)
            {
                Array.Reverse(bytes, offset, byteLength);
            }

            var   result = new T[byteLength / StructLength];
            ulong handle1;
            var   dstPointer = UnsafeUtility.PinGCArrayAndGetDataAddress(result, out handle1);

            try
            {
                fixed(void *srcPointer = &bytes[offset])
                {
                    UnsafeUtility.MemCpy(dstPointer, srcPointer, byteLength);
                }
            }
            finally
            {
                UnsafeUtility.ReleaseGCObject(handle1);
            }

            offset  += byteLength;
            readSize = offset - startOffset;
            return(result);
        }
        public global::GpuSkinningAnimClip Deserialize(byte[] bytes, int offset, global::MessagePack.IFormatterResolver formatterResolver, out int readSize)
        {
            if (global::MessagePack.MessagePackBinary.IsNil(bytes, offset))
            {
                readSize = 1;
                return(null);
            }

            var startOffset = offset;
            var length      = global::MessagePack.MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize);

            offset += readSize;

            var __name__       = default(string);
            var __startFrame__ = default(int);
            var __endFrame__   = default(int);

            for (int i = 0; i < length; i++)
            {
                var key = i;

                switch (key)
                {
                case 0:
                    __name__ = formatterResolver.GetFormatterWithVerify <string>().Deserialize(bytes, offset, formatterResolver, out readSize);
                    break;

                case 1:
                    __startFrame__ = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                    break;

                case 2:
                    __endFrame__ = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                    break;

                default:
                    readSize = global::MessagePack.MessagePackBinary.ReadNextBlock(bytes, offset);
                    break;
                }
                offset += readSize;
            }

            readSize = offset - startOffset;

            var ____result = new global::GpuSkinningAnimClip(__name__, __startFrame__, __endFrame__);

            ____result.name       = __name__;
            ____result.startFrame = __startFrame__;
            ____result.endFrame   = __endFrame__;
            return(____result);
        }
        public global::RM.Hotel.Models.Hotel Deserialize(byte[] bytes, int offset, global::MessagePack.IFormatterResolver formatterResolver, out int readSize)
        {
            if (global::MessagePack.MessagePackBinary.IsNil(bytes, offset))
            {
                throw new InvalidOperationException("typecode is null, struct not supported");
            }

            var startOffset = offset;
            var length      = global::MessagePack.MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize);

            offset += readSize;

            var __Name__  = default(string);
            var __Level__ = default(int);
            var __Rooms__ = default(global::System.Collections.Immutable.ImmutableList <global::RM.Hotel.Models.Room>);

            for (int i = 0; i < length; i++)
            {
                var key = i;

                switch (key)
                {
                case 0:
                    __Name__ = formatterResolver.GetFormatterWithVerify <string>().Deserialize(bytes, offset, formatterResolver, out readSize);
                    break;

                case 1:
                    __Level__ = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                    break;

                case 3:
                    __Rooms__ = formatterResolver.GetFormatterWithVerify <global::System.Collections.Immutable.ImmutableList <global::RM.Hotel.Models.Room> >().Deserialize(bytes, offset, formatterResolver, out readSize);
                    break;

                default:
                    readSize = global::MessagePack.MessagePackBinary.ReadNextBlock(bytes, offset);
                    break;
                }
                offset += readSize;
            }

            readSize = offset - startOffset;

            var ____result = new global::RM.Hotel.Models.Hotel();

            ____result.Name  = __Name__;
            ____result.Level = __Level__;
            ____result.Rooms = __Rooms__;
            return(____result);
        }
Exemple #29
0
            public CustomyEnumObject Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
            {
                var r = MessagePackBinary.ReadInt32(bytes, offset, out readSize);

                if (r == 0)
                {
                    return(CustomyEnumObject.A);
                }
                else if (r == 2)
                {
                    return(CustomyEnumObject.C);
                }
                return(CustomyEnumObject.B);
            }
        public global::RM.Hotel.Models.Stats Deserialize(byte[] bytes, int offset, global::MessagePack.IFormatterResolver formatterResolver, out int readSize)
        {
            if (global::MessagePack.MessagePackBinary.IsNil(bytes, offset))
            {
                throw new InvalidOperationException("typecode is null, struct not supported");
            }

            var startOffset = offset;
            var length      = global::MessagePack.MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize);

            offset += readSize;

            var __Level__ = default(int);
            var __Xp__    = default(int);
            var __Coins__ = default(int);

            for (int i = 0; i < length; i++)
            {
                var key = i;

                switch (key)
                {
                case 0:
                    __Level__ = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                    break;

                case 1:
                    __Xp__ = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                    break;

                case 2:
                    __Coins__ = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
                    break;

                default:
                    readSize = global::MessagePack.MessagePackBinary.ReadNextBlock(bytes, offset);
                    break;
                }
                offset += readSize;
            }

            readSize = offset - startOffset;

            var ____result = new global::RM.Hotel.Models.Stats();

            ____result.Level = __Level__;
            ____result.Xp    = __Xp__;
            ____result.Coins = __Coins__;
            return(____result);
        }