Ejemplo n.º 1
0
        public override MsgPackItem Read(MsgPackTypeId typeId, Stream data)
        {
            long len;

            if (!IsMasked(MsgPackTypeId.MpMap4, typeId, 0x0F, out len))
            {
                switch (typeId)
                {
                case MsgPackTypeId.MpMap16: len = ReadLen(data, 2); break;

                case MsgPackTypeId.MpMap32: len = ReadLen(data, 4); break;

                default: throw new MsgPackException(string.Concat("MpMap does not support a type ID of ", GetOfficialTypeName(typeId), "."), data.Position - 1, typeId);
                }
            }

            value = new KeyValuePair[len];

            for (int t = 0; t < len; t++)
            {
                MsgPackItem key = MsgPackItem.Unpack(data);
                MsgPackItem val = MsgPackItem.Unpack(data);
                value[t] = new KeyValuePair(key.Value, val.Value);
            }

            return(this);
        }
Ejemplo n.º 2
0
        public static object Deserialize(Type tType, Stream stream)
        {
            if (MsgPackSerializer.NativelySupportedTypes.Contains(tType))
            {
                return(MsgPackItem.Unpack(stream).Value);
            }
            MpMap  map    = (MpMap)MsgPackItem.Unpack(stream);
            object result = Materialize(tType, map);

            return(result);
        }