예제 #1
0
        public byte[] EncodeMessage <T>(T message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("The message which is to be serialized cannot be null.");
            }

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

            if (CompressionEnabled)
            {
                return(GZipCompression.Compress(raw));
            }
            else
            {
                return(raw);
            }
        }
예제 #2
0
        public object Decode(Type type, byte[] data, int offset, int count)
        {
            if (type == null)
            {
                throw new ArgumentNullException("The type to be deserialized cannot be null.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("The data to be deserialized cannot be null.");
            }

            if (CompressionEnabled)
            {
                return(ProtocolBuffersConvert.DeserializeObject(type, GZipCompression.Decompress(data, offset, count)));
            }
            else
            {
                return(ProtocolBuffersConvert.DeserializeObject(type, data, offset, count));
            }
        }