Beispiel #1
0
        protected override void WriteFramingExtras(OperationBuilder builder)
        {
            if (PreserveTtl)
            {
                Span <byte> preserveTtlByte = stackalloc byte[1];
                preserveTtlByte[0] = 5 << 4;
                builder.Write(preserveTtlByte);
            }

            if (DurabilityLevel == DurabilityLevel.None)
            {
                return;
            }

            // TODO: omit timeout bytes if no timeout provided
            Span <byte> bytes = stackalloc byte[2];

            var framingExtra = new FramingExtraInfo(RequestFramingExtraType.DurabilityRequirements, (byte)(bytes.Length - 1));

            bytes[0] = framingExtra.Byte;
            bytes[1] = (byte)DurabilityLevel;

            // TODO: improve timeout, coerce to 1500ms, etc
            //var timeout = DurabilityTimeout.HasValue ? DurabilityTimeout.Value.TotalMilliseconds : 0;
            //Converter.FromUInt16((ushort)timeout, bytes, 2);

            builder.Write(bytes);
        }
Beispiel #2
0
        public override void WriteExtras(OperationBuilder builder)
        {
            Span <byte> extras = stackalloc byte[4];

            ByteConverter.FromUInt32(Expires, extras);
            builder.Write(extras);
        }
Beispiel #3
0
        public override void WriteExtras(OperationBuilder builder)
        {
            Span <byte> extras = stackalloc byte[8];

            Flags       = Transcoder.GetFormat(Content);
            Format      = Flags.DataFormat;
            Compression = Flags.Compression;

            byte format      = (byte)Format;
            byte compression = (byte)Compression;

            BitUtils.SetBit(ref extras[0], 0, BitUtils.GetBit(format, 0));
            BitUtils.SetBit(ref extras[0], 1, BitUtils.GetBit(format, 1));
            BitUtils.SetBit(ref extras[0], 2, BitUtils.GetBit(format, 2));
            BitUtils.SetBit(ref extras[0], 3, BitUtils.GetBit(format, 3));
            BitUtils.SetBit(ref extras[0], 4, false);
            BitUtils.SetBit(ref extras[0], 5, BitUtils.GetBit(compression, 0));
            BitUtils.SetBit(ref extras[0], 6, BitUtils.GetBit(compression, 1));
            BitUtils.SetBit(ref extras[0], 7, BitUtils.GetBit(compression, 2));

            var typeCode = (ushort)Flags.TypeCode;

            ByteConverter.FromUInt16(typeCode, extras.Slice(2));
            ByteConverter.FromUInt32(Expires, extras.Slice(4));

            builder.Write(extras);
        }
        protected override void WriteExtras(OperationBuilder builder)
        {
            Span <byte> extras = stackalloc byte[1];

            extras[0] = 0x02;
            builder.Write(extras);
        }
        public virtual void WriteKey(OperationBuilder builder)
        {
            using (var bufferOwner = MemoryPool <byte> .Shared.Rent(OperationHeader.MaxKeyLength + Leb128.MaxLength))
            {
                var length = WriteKey(bufferOwner.Memory.Span);

                builder.Write(bufferOwner.Memory.Slice(0, length));
            }
        }
Beispiel #6
0
        protected override void WriteExtras(OperationBuilder builder)
        {
            Span <byte> extras = stackalloc byte[20];

            ByteConverter.FromUInt64(Delta, extras);
            ByteConverter.FromUInt64(Initial, extras.Slice(8));
            ByteConverter.FromUInt32(Expires, extras.Slice(16));
            builder.Write(extras);
        }
Beispiel #7
0
        protected override void WriteExtras(OperationBuilder builder)
        {
            Span <byte> extras = stackalloc byte[8];

            Flags = Transcoder.GetFormat(Content !);
            Flags.Write(extras);

            ByteConverter.FromUInt32(Expires, extras.Slice(4));

            builder.Write(extras);
        }
        protected override void WriteBody(OperationBuilder builder)
        {
            Span <byte> buffer = stackalloc byte[OperationHeader.MaxKeyLength + Leb128.MaxLength + 4];

            var keyLength = WriteKey(buffer.Slice(4));

            // ReSharper disable once PossibleInvalidOperationException
            ByteConverter.FromInt16(VBucketId.Value, buffer);
            ByteConverter.FromInt16((short)keyLength, buffer.Slice(2));

            builder.Write(buffer.Slice(0, keyLength + 4));
        }
Beispiel #9
0
        public override void WriteBody(OperationBuilder builder)
        {
            using (var bufferOwner = MemoryPool <byte> .Shared.Rent(OperationHeader.MaxKeyLength + Leb128.MaxLength + 4))
            {
                var buffer = bufferOwner.Memory.Span;

                var keyLength = WriteKey(buffer.Slice(4));

                // ReSharper disable once PossibleInvalidOperationException
                ByteConverter.FromInt16(VBucketId.Value, buffer);
                ByteConverter.FromInt16((short)keyLength, buffer.Slice(2));

                builder.Write(bufferOwner.Memory.Slice(0, keyLength + 4));
            }
        }
        public override void WriteBody(OperationBuilder builder)
        {
            var contentLength = Content.Length;

            using (var bufferOwner = MemoryPool <byte> .Shared.Rent(contentLength * 2))
            {
                var body = bufferOwner.Memory.Span;

                for (var i = 0; i < contentLength; i++)
                {
                    ByteConverter.FromInt16(Content[i], body);
                    body = body.Slice(2);
                }

                builder.Write(bufferOwner.Memory.Slice(0, contentLength * 2));
            }
        }
        public override void WriteFramingExtras(OperationBuilder builder)
        {
            if (DurabilityLevel == DurabilityLevel.None)
            {
                return;
            }

            // TODO: omit timeout bytes if no timeout provided
            Span <byte> bytes = stackalloc byte[4];

            var framingExtra = new FramingExtraInfo(RequestFramingExtraType.DurabilityRequirements, (byte)(bytes.Length - 1));

            bytes[0] = (byte)(framingExtra.Byte | (byte)0x03);
            bytes[1] = (byte)DurabilityLevel;

            var userTimeout = DurabilityTimeout.Value.TotalMilliseconds;

            ushort deadline;

            if (userTimeout >= ushort.MaxValue)
            {
                // -1 because 0xffff is going to be reserved by the cluster. 1ms less doesn't matter.
                deadline = ushort.MaxValue - 1;
            }
            else
            {
                // per spec 90% of the timeout is used as the deadline
                deadline = (ushort)(userTimeout * 0.9);
            }

            if (deadline < SyncReplicationTimeoutFloorMs)
            {
                // we need to ensure a floor value
                deadline = SyncReplicationTimeoutFloorMs;
            }

            ByteConverter.FromUInt16(deadline, bytes);
            builder.Write(bytes);
        }