Esempio n. 1
0
        protected override IGetOperationResult CreateResult(BinaryResponse response)
        {
            var retval = new GetOperationResult();

            if (response == null)
            {
                return(retval.NotFound(this));
            }

            if (response.StatusCode == 0)
            {
                var flags = NetworkOrderConverter.DecodeUInt32(response.Extra.Array, 0);

                retval.Value = new CacheItem((uint)flags, response.Data.Clone());
            }

            return(retval.WithResponse(response));
        }
        /// <summary>
        /// Returns true if further IO is pending. (ie. body must be read)
        /// </summary>
        /// <param name="header"></param>
        /// <param name="bodyLength"></param>
        /// <param name="extraLength"></param>
        /// <returns></returns>
        private bool ProcessHeader(byte[] header)
        {
            if (header[Protocol.HEADER_INDEX_MAGIC] != Protocol.ResponseMagic)
            {
                throw new InvalidOperationException($"Expected magic value {Protocol.ResponseMagic}, received: {header[Protocol.HEADER_INDEX_MAGIC]}");
            }

            // TODO test if unsafe array gives a perf boost
            OpCode        = header[Protocol.HEADER_INDEX_OPCODE];
            KeyLength     = NetworkOrderConverter.DecodeUInt16(header, Protocol.HEADER_INDEX_KEY);
            DataType      = header[Protocol.HEADER_INDEX_DATATYPE];
            StatusCode    = NetworkOrderConverter.DecodeUInt16(header, Protocol.HEADER_INDEX_STATUS);
            CorrelationId = NetworkOrderConverter.DecodeUInt32(header, Protocol.HEADER_INDEX_OPAQUE);
            CAS           = NetworkOrderConverter.DecodeUInt64(header, Protocol.HEADER_INDEX_CAS);

            var bodyLength = (int)NetworkOrderConverter.DecodeUInt32(header, Protocol.HEADER_INDEX_BODY_LENGTH);

            if (bodyLength > 0)
            {
                var extraLength = header[Protocol.HEADER_INDEX_EXTRA];
                if (extraLength > 0)
                {
                    Extra = ByteBuffer.Allocate(allocator, extraLength);
                }

                var dataLength = bodyLength - extraLength;
                if (dataLength > 0)
                {
                    Data = ByteBuffer.Allocate(allocator, dataLength);
                }

                return(true);
            }

            return(false);
        }