Пример #1
0
        private unsafe void DeserializeHeader(byte[] header, out int dataLength, out int extraLength)
        {
            fixed(byte *buffer = header)
            {
                if (buffer[0] != MAGIC_VALUE)
                {
                    throw new InvalidOperationException("Expected magic value " + MAGIC_VALUE + ", received: " + buffer[0]);
                }

                this.DataType   = buffer[HEADER_DATATYPE];
                this.Opcode     = buffer[HEADER_OPCODE];
                this.StatusCode = BinaryConverter.DecodeUInt16(buffer, HEADER_STATUS);

                this.KeyLength     = BinaryConverter.DecodeUInt16(buffer, HEADER_KEY);
                this.CorrelationId = BinaryConverter.DecodeInt32(buffer, HEADER_OPAQUE);
                this.CAS           = BinaryConverter.DecodeUInt64(buffer, HEADER_CAS);

                dataLength  = BinaryConverter.DecodeInt32(buffer, HEADER_BODY);
                extraLength = buffer[HEADER_EXTRA];
            }
        }
Пример #2
0
        protected override IOperationResult ProcessResponse(BinaryResponse response)
        {
            var result = new BinaryOperationResult();
            var status = response.StatusCode;

            this.StatusCode = status;

            if (status == 0)
            {
                var data = response.Data;
                if (data.Count != 8)
                {
                    return(result.Fail("Result must be 8 bytes long, received: " + data.Count, new InvalidOperationException()));
                }

                this.result = BinaryConverter.DecodeUInt64(data.Array, data.Offset);

                return(result.Pass());
            }

            var message = ResultHelper.ProcessResponseData(response.Data);

            return(result.Fail(message));
        }