/// <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, out int bodyLength) { #if DEBUG if (header[Protocol.HEADER_INDEX_MAGIC] != Protocol.ResponseMagic) { throw new InvalidOperationException("Expected magic value " + Protocol.ResponseMagic + ", received: " + header[Protocol.HEADER_INDEX_MAGIC]); } #endif // 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 = unchecked ((uint)NetworkOrderConverter.DecodeInt32(header, Protocol.HEADER_INDEX_OPAQUE)); CAS = NetworkOrderConverter.DecodeUInt64(header, Protocol.HEADER_INDEX_CAS); bodyLength = NetworkOrderConverter.DecodeInt32(header, Protocol.HEADER_INDEX_BODY); if (bodyLength > 0) { var extraLength = header[Protocol.HEADER_INDEX_EXTRA]; data = allocator.Take(bodyLength); Extra = new ArraySegment <byte>(data, 0, extraLength); Data = new ArraySegment <byte>(data, extraLength, bodyLength - extraLength); return(true); } return(false); }
protected override IMutateOperationResult CreateResult(BinaryResponse response) { var retval = new MutateOperationResult(); if (response == null) { return(retval.NotFound(this)); } if (response.Success) { var data = response.Data; if (data.Count != ResultLength) { return(retval.Failed(this, new InvalidOperationException("Result must be " + ResultLength + " bytes long, received: " + data.Count))); } retval.Value = NetworkOrderConverter.DecodeUInt64(data.Array, data.Offset); } 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); }