Exemplo n.º 1
0
        public T Decode <T>(byte[] data, int offset, int count)
        {
            if (data == null)
            {
                throw new ArgumentNullException("The data to be deserialized cannot be null.");
            }

            if (CompressionEnabled)
            {
                return(ProtocolBuffersConvert.DeserializeObject <T>(GZipCompression.Decompress(data, offset, count)));
            }
            else
            {
                return(ProtocolBuffersConvert.DeserializeObject <T>(data, offset, count));
            }
        }
Exemplo n.º 2
0
        public T DecodeMessage <T>(byte[] data, int dataOffset, int dataLength)
        {
            if (data == null)
            {
                throw new ArgumentNullException("The data which is to be deserialized cannot be null.");
            }

            if (CompressionEnabled)
            {
                return(ProtocolBuffersConvert.DeserializeObject <T>(GZipCompression.Decompress(data, dataOffset, dataLength)));
            }
            else
            {
                return(ProtocolBuffersConvert.DeserializeObject <T>(data, dataOffset, dataLength));
            }
        }
Exemplo n.º 3
0
        public byte[] Encode <T>(T obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("The object to be serialized cannot be null.");
            }

            var raw = ProtocolBuffersConvert.SerializeObject <T>(obj);

            if (CompressionEnabled)
            {
                return(GZipCompression.Compress(raw));
            }
            else
            {
                return(raw);
            }
        }
Exemplo n.º 4
0
        public byte[] EncodeMessage(object message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("The message which is to be serialized cannot be null.");
            }

            var raw = ProtocolBuffersConvert.SerializeObject(message);

            if (CompressionEnabled)
            {
                return(GZipCompression.Compress(raw));
            }
            else
            {
                return(raw);
            }
        }