Example #1
0
        protected internal override System.Collections.Generic.IList <ArraySegment <byte> > GetBuffer()
        {
            // todo adjust the size to fit a request using a fnv hashed key
            var sb      = new StringBuilder(128);
            var buffers = new List <ArraySegment <byte> >(3);

            switch (this.command)
            {
            case StoreCommand.Add: sb.Append("add "); break;

            case StoreCommand.Replace: sb.Append("replace "); break;

            case StoreCommand.Set: sb.Append("set "); break;

            case StoreCommand.Append: sb.Append("append "); break;

            case StoreCommand.Prepend: sb.Append("prepend "); break;

            case StoreCommand.CheckAndSet: sb.Append("cas "); break;

            default: throw new MemcachedClientException(command + " is not supported.");
            }

            sb.Append(this.Key);
            sb.Append(" ");
            sb.Append(this.value.Flags.ToString(CultureInfo.InvariantCulture));
            sb.Append(" ");
            sb.Append(this.expires.ToString(CultureInfo.InvariantCulture));
            sb.Append(" ");

            var data = this.value.Data;

            sb.Append(Convert.ToString(data.Count, CultureInfo.InvariantCulture));

            if (command == StoreCommand.CheckAndSet)
            {
                sb.Append(" ");
                sb.Append(Convert.ToString(this.cas, CultureInfo.InvariantCulture));
            }

            sb.Append(TextSocketHelper.CommandTerminator);

            TextSocketHelper.GetCommandBuffer(sb.ToString(), buffers);
            buffers.Add(data);
            buffers.Add(StoreOperationBase.DataTerminator);

            return(buffers);
        }