Ejemplo n.º 1
0
        protected RequestEntity GetRequestEntity(byte[] bytes)
        {
            using (var stream = new MemoryStream(bytes))
            {
                var reader = new BinaryReader(stream);

                var headerLen = reader.ReadInt32();
                stream.Seek(headerLen, SeekOrigin.Current);

                var compression = reader.ReadByte();

                var dataLen   = reader.ReadInt32();
                var dataBytes = reader.ReadBytes(dataLen);

                switch (compression)
                {
                case 1:
                    dataBytes = CompressionUtil.DecompressDef(dataBytes);
                    break;

                case 2:
                    dataBytes = CompressionUtil.DecompressLZ(dataBytes, false);
                    break;
                }

                var entity = SerializationUtil.Deserialize <RequestEntity>(dataBytes);
                return(entity);
            }
        }
Ejemplo n.º 2
0
        private static ResponseEntity GetResponseEntity(byte[] bytes)
        {
            using (var stream = new MemoryStream(bytes))
            {
                var reader      = new BinaryReader(stream);
                var compression = reader.ReadByte();

                var dataLen   = reader.ReadInt32();
                var dataBytes = reader.ReadBytes(dataLen);

                switch (compression)
                {
                case 1:
                    dataBytes = CompressionUtil.DecompressDef(dataBytes);
                    break;

                case 2:
                    dataBytes = CompressionUtil.DecompressLZ(dataBytes, false);
                    break;
                }

                var responseEntity = SerializationUtil.Deserialize <ResponseEntity>(dataBytes);
                return(responseEntity);
            }
        }