示例#1
0
        public object Deserialize(ISerializedContainer container, Type type)
        {
            var psc = container as ProtobufSerializedContainer;

            if (psc == null)
            {
                throw new ArgumentException("Invalid container type. Use the GenerateContainer method.");
            }

            return(Deserialize(psc.Stream, type));
        }
示例#2
0
        public void Serialize(ISerializedContainer container, object value, Type type)
        {
            var jTokenContainer = container as JArrayContainer;

            if (jTokenContainer == null)
            {
                throw new ArgumentException("Invalid container. Use the GenerateContainer method.");
            }

            using (var writer = jTokenContainer.Array.CreateWriter())
                _serializer.Serialize(writer, value, type);
        }
示例#3
0
        public void Serialize(ISerializedContainer container, object value, Type type)
        {
            var psc = container as ProtobufSerializedContainer;

            if (psc == null)
            {
                throw new ArgumentException("Invalid container type. Use the GenerateContainer method.");
            }

            Serialize(psc.Stream, value, type);
            psc.Count++;
        }
        public void Serialize(ISerializedContainer container, object value, Type type)
        {
            var psc = container as MsgPackSerializedContainer;

            if (psc == null)
            {
                throw new ArgumentException("Invalid container type. Use the GenerateContainer method.");
            }

            var bytes = _context.GetSerializer(type).PackSingleObject(value);             // TODO: use recyclable memory pool

            psc.Queue.Enqueue(bytes);
        }
        public object Deserialize(ISerializedContainer container, Type type)
        {
            var psc = container as MsgPackSerializedContainer;

            if (psc == null)
            {
                throw new ArgumentException("Invalid container type. Use the GenerateContainer method.");
            }

            byte[] bytes;
            if (!psc.Queue.TryDequeue(out bytes))
            {
                throw new InvalidDataException("No data available in the container.");
            }

            return(_context.GetSerializer(type).UnpackSingleObject(bytes));
        }
示例#6
0
        public object Deserialize(ISerializedContainer container, Type type)
        {
            var jTokenContainer = container as JArrayContainer;

            if (jTokenContainer == null)
            {
                throw new ArgumentException("Invalid container. Use the GenerateContainer method.");
            }

            if (jTokenContainer.Array.HasValues)
            {
                var first = jTokenContainer.Array.First;
                first.Remove();
                using (var reader = first.CreateReader())
                    return(_serializer.Deserialize(reader, type));
            }
            return(null);
        }
示例#7
0
        public void Serialize(ISerializedContainer container, object value, Type type)
        {
            var psc = container as ProtobufSerializedContainer;

            if (psc == null)
            {
                throw new ArgumentException("Invalid container type. Use the GenerateContainer method.");
            }

#if DNX451 || NET45
            using (var stream = _streamManager.GetStream("ProtobufSerialize"))
#else
            using (var stream = new MemoryStream())
#endif
            {
                Serialize(stream, value, type);
                psc.Queue.Enqueue(stream.ToArray());
            }
        }
示例#8
0
        public object Deserialize(ISerializedContainer container, Type type)
        {
            var psc = container as ProtobufSerializedContainer;

            if (psc == null)
            {
                throw new ArgumentException("Invalid container type. Use the GenerateContainer method.");
            }

            byte[] bytes;
            if (!psc.Queue.TryDequeue(out bytes))
            {
                throw new InvalidDataException("No data available in the container.");
            }

#if DNX451 || NET45
            using (var ms = _streamManager.GetStream("ProtobufDeserialize", bytes, 0, bytes.Length))
#else
            using (var ms = new MemoryStream(bytes, false))
#endif
                return(Deserialize(ms, type));
        }
示例#9
0
 public void Serialize <T>(ISerializedContainer container, T value)
 {
     Serialize(container, value, typeof(T));
 }
示例#10
0
 public T Deserialize <T>(ISerializedContainer container)
 {
     return((T)Deserialize(container, typeof(T)));
 }