protected override INodeStatsOperationResult CreateResult(BinaryResponse response)
        {
            if (stats == null)
            {
                stats = new Dictionary <string, string>();
            }

            var data = response.Data;

            // if empty key (last response packet response)
            // or if error
            // return the response object to break the loop and let the node process the next op.
            if (response.KeyLength == 0 || !response.Success)
            {
                return(new NodeStatsOperationResult {
                    Value = stats
                }.WithResponse(response));
            }

            // decode stat key/value
            var key   = NetworkOrderConverter.DecodeKey(data.Array, data.Offset, response.KeyLength);
            var value = NetworkOrderConverter.DecodeKey(data.Array, data.Offset + response.KeyLength, data.Count - response.KeyLength);

            stats[key] = value;

            return(null);            // we expect more response packets
        }
예제 #2
0
        protected override INodeStatsOperationResult CreateResult(BinaryResponse response)
        {
            if (stats == null)
            {
                stats = new Dictionary <string, string>();
            }

            var data = response.Data;

            // if empty key (last response packet)
            // or if error
            // return the response object to break the loop and let the node process the next op.
            if (response.KeyLength == 0 || !response.Success)
            {
                return(new NodeStatsOperationResult {
                    Value = stats
                }.WithResponse(response));
            }

            // decode stat key/value
            // both are ASCII in memcached
            var key   = Encoding.ASCII.GetString(data.Array, 0, response.KeyLength);
            var value = Encoding.ASCII.GetString(data.Array, response.KeyLength, data.Length - response.KeyLength);

            stats[key] = value;

            return(null);            // we expect more response packets
        }
예제 #3
0
        protected override IOperationResult CreateResult(BinaryResponse response)
        {
            var retval = new BinaryOperationResult();

            return(response == null
                                        ? retval.Success(this)
                                        : retval.WithResponse(response));
        }
		public static BinaryOperationResult FromResponse(BinaryResponse response, string failMessage = null)
		{
			var success = response.StatusCode == 0;

			var retval = new BinaryOperationResult
			{
				StatusCode = response.StatusCode,
				Success = success,
				Message = success ? null : response.GetStatusMessage() ?? failMessage,
				Cas = response.CAS
			};

			return retval;
		}
예제 #5
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));
        }
예제 #6
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.DecodeInt32(response.Extra.Array, 0);
                // HACK
                var copy = new PooledSegment(Allocator, response.Data.Count);
                Buffer.BlockCopy(response.Data.Array, response.Data.Offset, copy.Array, 0, copy.Count);
                retval.Value = new CacheItem((uint)flags, copy);
            }

            return(retval.WithResponse(response));
        }
        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));
        }
 protected abstract TResult CreateResult(BinaryResponse response);
예제 #9
0
        protected override IOperationResult CreateResult(BinaryResponse response)
        {
            Debug.Assert(response != null);

            return(BinaryOperationResult.FromResponse(response));
        }
예제 #10
0
 protected override IOperationResult CreateResult(BinaryResponse response)
 {
     return(new BinaryOperationResult().WithResponse(response, "Failed to read response"));
 }