/// <inheritdoc/>
        public override bool InPlaceUpdater(ref SpanByte key, ref SpanByte input, ref SpanByte value)
        {
            long curr = Utils.BytesToLong(value.AsSpan());
            long next = curr + Utils.BytesToLong(input.AsSpan());

            if (Utils.NumDigits(next) > value.Length)
            {
                return(false);
            }
            Utils.LongToBytes(next, value.AsSpan());
            return(true);
        }
        /// <inheritdoc/>
        public override void CopyUpdater(ref SpanByte key, ref SpanByte input, ref SpanByte oldValue, ref SpanByte newValue)
        {
            long curr = Utils.BytesToLong(oldValue.AsSpan());
            long next = curr + Utils.BytesToLong(input.AsSpan());

            Debug.Assert(Utils.NumDigits(next) == newValue.Length, "Unexpected destination length in CopyUpdater");
            Utils.LongToBytes(next, newValue.AsSpan());
        }
        /// <inheritdoc/>
        public override bool CopyUpdater(ref SpanByte key, ref SpanByte input, ref SpanByte oldValue, ref SpanByte newValue, ref SpanByteAndMemory output, ref RMWInfo rmwInfo)
        {
            long curr = Utils.BytesToLong(oldValue.AsSpan());
            long next = curr + Utils.BytesToLong(input.AsSpan());

            Debug.Assert(Utils.NumDigits(next) == newValue.Length, "Unexpected destination length in CopyUpdater");
            Utils.LongToBytes(next, newValue.AsSpan());
            return(true);
        }
Exemple #4
0
        public unsafe void SpanByteUnitTest1()
        {
            Span <byte> payload    = stackalloc byte[20];
            Span <byte> serialized = stackalloc byte[24];

            SpanByte sb = SpanByte.FromFixedSpan(payload);

            Assert.IsFalse(sb.Serialized);
            Assert.AreEqual(20, sb.Length);
            Assert.AreEqual(24, sb.TotalSize);
            Assert.AreEqual(20, sb.AsSpan().Length);
            Assert.AreEqual(20, sb.AsReadOnlySpan().Length);

            fixed(byte *ptr = serialized)
            sb.CopyTo(ptr);

            ref SpanByte ssb = ref SpanByte.ReinterpretWithoutLength(serialized);