Exemplo n.º 1
0
        protected override BinaryRequest Build()
        {
            OpCode op;
            switch (this.mode)
            {
                case StoreMode.Add: op = OpCode.Add; break;
                case StoreMode.Set: op = OpCode.Set; break;
                case StoreMode.Replace: op = OpCode.Replace; break;
                default: throw new ArgumentOutOfRangeException("mode", mode + " is not supported");
            }

            var extra = new byte[8];

            BinaryConverter.EncodeUInt32((uint)this.value.Flags, extra, 0);
            BinaryConverter.EncodeUInt32(expires, extra, 4);

            var request = new BinaryRequest(op)
            {
                Key = this.Key,
                Cas = this.Cas,
                Extra = new ArraySegment<byte>(extra),
                Data = this.value.Data
            };

            return request;
        }
Exemplo n.º 2
0
        protected override BinaryRequest Build()
        {
            OpCode op;

            switch (this.mode)
            {
            case StoreMode.Add: op = OpCode.Add; break;

            case StoreMode.Set: op = OpCode.Set; break;

            case StoreMode.Replace: op = OpCode.Replace; break;

            default: throw new ArgumentOutOfRangeException("mode", mode + " is not supported");
            }

            var extra = new byte[8];

            BinaryConverter.EncodeUInt32((uint)this.value.Flags, extra, 0);
            BinaryConverter.EncodeUInt32(expires, extra, 4);

            var request = new BinaryRequest(op)
            {
                Key   = this.Key,
                Cas   = this.Cas,
                Extra = new ArraySegment <byte>(extra),
                Data  = this.value.Data
            };

            return(request);
        }
Exemplo n.º 3
0
        protected override BinaryRequest Build()
        {
            var request = new BinaryRequest(OpCode.Stat);
            if (!String.IsNullOrEmpty(this.type))
                request.Key = this.type;

            return request;
        }
Exemplo n.º 4
0
		protected override BinaryRequest Build()
		{
			var request = new BinaryRequest(OpCode.Stat);
			if (!String.IsNullOrEmpty(this.type))
				request.Key = this.type;

			return request;
		}
        protected override BinaryRequest Build(string key)
        {
            var request = new BinaryRequest(OpCode.GetQ)
            {
                Key = key
            };

            return(request);
        }
Exemplo n.º 6
0
		protected override BinaryRequest Build(string key)
		{
			var request = new BinaryRequest(OpCode.GetQ)
			{
				Key = key
			};

			return request;
		}
Exemplo n.º 7
0
        protected override BinaryRequest Build()
        {
            var request = new BinaryRequest(OpCode.Delete)
            {
                Key = this.Key,
                Cas = this.Cas
            };

            return(request);
        }
Exemplo n.º 8
0
        protected override BinaryRequest Build()
        {
            var request = new BinaryRequest(OpCode.SaslStep)
            {
                Key  = this.Provider.Type,
                Data = new ArraySegment <byte>(this.Provider.Continue(this.continuation))
            };

            return(request);
        }
Exemplo n.º 9
0
        protected override BinaryRequest Build()
        {
            var request = new BinaryRequest(OpCode.Delete)
            {
                Key = this.Key,
                Cas = this.Cas
            };

            return request;
        }
Exemplo n.º 10
0
        protected override BinaryRequest Build()
        {
            var request = new BinaryRequest(OpCode.SaslStep)
            {
                Key = this.Provider.Type,
                Data = new ArraySegment<byte>(this.Provider.Continue(this.continuation))
            };

            return request;
        }
Exemplo n.º 11
0
        protected override BinaryRequest Build()
        {
            // create a Sasl Start command
            var request = new BinaryRequest(OpCode.SaslStart)
            {
                Key = this.Provider.Type,
                Data = new ArraySegment<byte>(this.Provider.Authenticate())
            };

            return request;
        }
Exemplo n.º 12
0
        protected override BinaryRequest Build()
        {
            var request = new BinaryRequest((OpCode)this.mode)
            {
                Key  = this.Key,
                Cas  = this.Cas,
                Data = this.data
            };

            return(request);
        }
		protected override BinaryRequest Build()
		{
			var request = new BinaryRequest((OpCode)this.mode)
			{
				Key = this.Key,
				Cas = this.Cas,
				Data = this.data
			};

			return request;
		}
Exemplo n.º 14
0
        protected override BinaryRequest Build()
        {
            // create a Sasl Start command
            var request = new BinaryRequest(OpCode.SaslStart)
            {
                Key  = this.Provider.Type,
                Data = new ArraySegment <byte>(this.Provider.Authenticate())
            };

            return(request);
        }
Exemplo n.º 15
0
        protected override BinaryRequest Build()
        {
            var request = new BinaryRequest((OpCode)this.mode)
            {
                Key = this.Key,
                Cas = this.Cas
            };

            this.UpdateExtra(request);

            return request;
        }
Exemplo n.º 16
0
        protected override BinaryRequest Build()
        {
            var request = new BinaryRequest((OpCode)this.mode)
            {
                Key = this.Key,
                Cas = this.Cas
            };

            this.UpdateExtra(request);

            return(request);
        }
        protected unsafe void UpdateExtra(BinaryRequest request)
        {
            byte[] extra = new byte[20];

            fixed(byte *buffer = extra)
            {
                BinaryConverter.EncodeUInt64(this._delta, buffer, 0);
                BinaryConverter.EncodeUInt64(this._defaultValue, buffer, 8);
                BinaryConverter.EncodeUInt32(this._expires, buffer, 16);
            }

            request.Extra = new ArraySegment <byte>(extra);
        }
Exemplo n.º 18
0
        protected unsafe void UpdateExtra(BinaryRequest request)
        {
            byte[] extra = new byte[20];

            fixed (byte* buffer = extra)
            {
                BinaryConverter.EncodeUInt64(this.delta, buffer, 0);

                BinaryConverter.EncodeUInt64(this.defaultValue, buffer, 8);
                BinaryConverter.EncodeUInt32(this.expires, buffer, 16);
            }

            request.Extra = new ArraySegment<byte>(extra);
        }
Exemplo n.º 19
0
        protected override BinaryRequest Build()
        {
            var extra = new byte[4];

            BinaryConverter.EncodeUInt32(expires, extra, 0);

            var request = new BinaryRequest(OpCode.Touch)
            {
                Key   = this.Key,
                Extra = new ArraySegment <byte>(extra)
            };

            return(request);
        }
Exemplo n.º 20
0
        protected override BinaryRequest Build()
        {
            var op = (byte)CouchbaseOpCode.Unlock;
            var request = new BinaryRequest(op);

            if (this.locator != null)
            {
                request.Reserved = (ushort)locator.GetIndex(this.Key);

                if (log.IsDebugEnabled) log.DebugFormat("Key {0} was mapped to {1}", this.Key, request.Reserved);
            }

            request.Key = Key;
            request.Cas = Cas;

            return request;
        }
        protected internal override IList <ArraySegment <byte> > GetBuffer()
        {
            var keys = this.Keys;

            if (keys == null || keys.Count == 0)
            {
                if (log.IsWarnEnabled)
                {
                    log.Warn("Empty multiget!");
                }

                return(new ArraySegment <byte> [0]);
            }

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Building multi-get for {0} keys", keys.Count);
            }

            // map the command's correlationId to the item key,
            // so we can use GetQ (which only returns the item data)
            this.idToKey = new Dictionary <int, string>();

            // get ops have 2 segments, header + key
            var buffers = new List <ArraySegment <byte> >(keys.Count * 2);

            foreach (var key in keys)
            {
                var request = this.Build(key);

                request.CreateBuffer(buffers);

                // we use this to map the responses to the keys
                idToKey[request.CorrelationId] = key;
            }

            // uncork the server
            var noop = new BinaryRequest(OpCode.NoOp);

            this.noopId = noop.CorrelationId;

            noop.CreateBuffer(buffers);

            return(buffers);
        }
Exemplo n.º 22
0
        protected override BinaryRequest Build()
        {
            var retval = new BinaryRequest(0x1c);

            retval.Key = this.Key;

            if (this.locator != null)
            {
                retval.Reserved = (ushort)locator.GetIndex(this.Key);
                if (log.IsDebugEnabled) log.DebugFormat("Key {0} was mapped to {1}", this.Key, retval.Reserved);
            }

            var extra = new byte[4];

            BinaryConverter.EncodeUInt32(this.expires, extra, 0);
            retval.Extra = new ArraySegment<byte>(extra);

            return retval;
        }
Exemplo n.º 23
0
        protected internal override IList<ArraySegment<byte>> GetBuffer()
        {
            var keys = this.Keys;

            if (keys == null || keys.Count == 0)
            {
                if (log.IsWarnEnabled) log.Warn("Empty multiget!");

                return new ArraySegment<byte>[0];
            }

            if (log.IsDebugEnabled)
                log.DebugFormat("Building multi-get for {0} keys", keys.Count);

            // map the command's correlationId to the item key,
            // so we can use GetQ (which only returns the item data)
            this.idToKey = new Dictionary<int, string>();

            // get ops have 2 segments, header + key
            var buffers = new List<ArraySegment<byte>>(keys.Count * 2);

            foreach (var key in keys)
            {
                var request = this.Build(key);

                request.CreateBuffer(buffers);

                // we use this to map the responses to the keys
                idToKey[request.CorrelationId] = key;
            }

            // uncork the server
            var noop = new BinaryRequest(OpCode.NoOp);
            this.noopId = noop.CorrelationId;

            noop.CreateBuffer(buffers);

            return buffers;
        }
Exemplo n.º 24
0
        protected unsafe void UpdateExtra(BinaryRequest request)
        {
            if (mode == MutationMode.Touch)
            {
                Span <byte> extra = stackalloc byte[4];
                BinaryPrimitives.WriteUInt32BigEndian(extra, this.expires);
                request.Extra = new ArraySegment <byte>(extra.ToArray());
            }
            else
            {
                byte[] extra = new byte[20];

                fixed(byte *buffer = extra)
                {
                    BinaryConverter.EncodeUInt64(this.delta, buffer, 0);

                    BinaryConverter.EncodeUInt64(this.defaultValue, buffer, 8);
                    BinaryConverter.EncodeUInt32(this.expires, buffer, 16);
                }

                request.Extra = new ArraySegment <byte>(extra);
            }
        }
Exemplo n.º 25
0
        protected override BinaryRequest Build()
        {
            var request = new BinaryRequest(OpCode.Flush);

            return(request);
        }
Exemplo n.º 26
0
        protected override BinaryRequest Build()
        {
            var request = new BinaryRequest(0x96)
            {
                Data = this.BuildBody()
            };

            return request;
        }
Exemplo n.º 27
0
        protected override BinaryRequest Build()
        {
            var request = new BinaryRequest(OpCode.Flush);

            return request;
        }