public static DecodeInt32 ( ArraySegment |
||
segment | ArraySegment |
|
offset | int | |
Результат | int |
protected override bool ProcessResponse(BinaryResponse response) { if (response.StatusCode == 0) { int flags = BinaryConverter.DecodeInt32(response.Extra, 0); this.result = new CacheItem((ushort)flags, response.Data); this.Cas = response.CAS; #if EVEN_MORE_LOGGING if (log.IsDebugEnabled) { log.DebugFormat("Get succeeded for key '{0}'.", this.Key); } #endif return(true); } this.Cas = 0; #if EVEN_MORE_LOGGING if (log.IsDebugEnabled) { log.DebugFormat("Get failed for key '{0}'. Reason: {1}", this.Key, Encoding.ASCII.GetString(response.Data.Array, response.Data.Offset, response.Data.Count)); } #endif return(false); }
protected override IOperationResult ProcessResponse(BinaryResponse response) { var status = response.StatusCode; var result = new BinaryOperationResult(); this.StatusCode = status; if (status == 0) { int flags = BinaryConverter.DecodeInt32(response.Extra, 0); this.result = new CacheItem((ushort)flags, response.Data); this.Cas = response.CAS; #if EVEN_MORE_LOGGING if (_logger.IsEnabled(LogLevel.Debug)) { _logger.LogDebug("Get succeeded for key '{0}'.", this.Key); } #endif return(result.Pass()); } this.Cas = 0; #if EVEN_MORE_LOGGING if (_logger.IsEnabled(LogLevel.Debug)) { _logger.LogDebug("Get failed for key '{0}'. Reason: {1}", this.Key, Encoding.ASCII.GetString(response.Data.Array, response.Data.Offset, response.Data.Count)); } #endif var message = ResultHelper.ProcessResponseData(response.Data); return(result.Fail(message)); }
public static unsafe int DecodeInt32(ArraySegment <byte> segment, int offset) { fixed(byte *buffer = segment.Array) { byte *ptr = buffer + segment.Offset + offset; return(BinaryConverter.DecodeInt32(buffer, 0)); } }
protected override IOperationResult ProcessResponse(BinaryResponse response) { var status = response.StatusCode; var result = new BinaryOperationResult(); this.StatusCode = status; if (status == 0) { int flags = BinaryConverter.DecodeInt32(response.Extra, 0); this.result = new CacheItem((ushort)flags, response.Data); this.Cas = response.CAS; return(result.Pass()); } this.Cas = 0; return(result.Fail(OperationResultHelper.ProcessResponseData(response.Data))); }
protected internal override IOperationResult ReadResponse(PooledSocket socket) { this.result = new Dictionary <string, CacheItem>(); this.Cas = new Dictionary <string, ulong>(); var result = new TextOperationResult(); var response = new BinaryResponse(); while (response.Read(socket)) { this.StatusCode = response.StatusCode; // found the noop, quit if (response.CorrelationId == this.noopId) { return(result.Pass()); } string key; // find the key to the response if (!this.idToKey.TryGetValue(response.CorrelationId, out key)) { // we're not supposed to get here tho log.WarnFormat("Found response with CorrelationId {0}, but no key is matching it.", response.CorrelationId); continue; } if (log.IsDebugEnabled) { log.DebugFormat("Reading item {0}", key); } // deserialize the response int flags = BinaryConverter.DecodeInt32(response.Extra, 0); this.result[key] = new CacheItem((ushort)flags, response.Data); this.Cas[key] = response.CAS; } // finished reading but we did not find the NOOP return(result.Fail("Found response with CorrelationId {0}, but no key is matching it.")); }
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}\" but 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]; } }
private void StoreResult(BinaryResponse reader) { string key; // find the key to the response if (!this.idToKey.TryGetValue(reader.CorrelationId, out key)) { // we're not supposed to get here tho log.WarnFormat("Found response with CorrelationId {0}, but no key is matching it.", reader.CorrelationId); } else { if (log.IsDebugEnabled) { log.DebugFormat("Reading item {0}", key); } // deserialize the response var flags = (ushort)BinaryConverter.DecodeInt32(reader.Extra, 0); this.result[key] = new CacheItem(flags, reader.Data); this.Cas[key] = reader.CAS; } }
public unsafe bool Read(PooledSocket socket) { if (!socket.IsAlive) { this.StatusCode = -1; return(false); } byte[] header = new byte[24]; socket.Read(header, 0, 24); #if DEBUG_PROTOCOL if (log.IsDebugEnabled) { log.Debug("Received binary response"); StringBuilder sb = new StringBuilder(128).AppendLine(); for (int i = 0; i < header.Length; i++) { byte value = header[i]; sb.Append(value < 16 ? "0x0" : "0x").Append(value.ToString("X")); if (i % 4 == 3) { sb.AppendLine(); } else { sb.Append(" "); } } log.Debug(sb.ToString()); } #endif fixed(byte *buffer = header) { if (buffer[0] != MAGIC_VALUE) { throw new InvalidOperationException("Expected magic value " + MAGIC_VALUE + ", received: " + buffer[0]); } int remaining = BinaryConverter.DecodeInt32(buffer, HEADER_BODY); int extraLength = buffer[HEADER_EXTRA]; byte[] data = new byte[remaining]; socket.Read(data, 0, remaining); this.Extra = new ArraySegment <byte>(data, 0, extraLength); this.Data = new ArraySegment <byte>(data, extraLength, data.Length - extraLength); this.DataType = buffer[HEADER_DATATYPE]; this.Opcode = buffer[HEADER_OPCODE]; this.StatusCode = BinaryConverter.DecodeInt16(buffer, HEADER_STATUS); this.KeyLength = BinaryConverter.DecodeInt16(buffer, HEADER_KEY); this.CorrelationId = BinaryConverter.DecodeInt32(buffer, HEADER_OPAQUE); this.CAS = BinaryConverter.DecodeUInt64(buffer, HEADER_CAS); } return(this.StatusCode == 0); }