Beispiel #1
0
        public Result GetKeyValueSize(out int keySize, out int valueSize)
        {
            Unsafe.SkipInit(out keySize);
            Unsafe.SkipInit(out valueSize);

            // This should only be called after ReadEntryCount.
            Assert.NotEqual(_offset, 0);

            // Peek the next entry header.
            KeyValueArchiveEntryHeader header = default;

            Result rc = Peek(SpanHelpers.AsByteSpan(ref header));

            if (rc.IsFailure())
            {
                return(rc);
            }

            if (!header.IsValid())
            {
                return(ResultKvdb.InvalidKeyValue.Log());
            }

            keySize   = header.KeySize;
            valueSize = header.ValueSize;

            return(Result.Success);
        }
Beispiel #2
0
        public void WriteEntry(ReadOnlySpan <byte> key, ReadOnlySpan <byte> value)
        {
            // This should only be called after writing header.
            Assert.SdkNotEqual(_offset, 0);

            var header = new KeyValueArchiveEntryHeader(key.Length, value.Length);

            Write(SpanHelpers.AsByteSpan(ref header));
            Write(key);
            Write(value);
        }
Beispiel #3
0
        public Result ReadKeyValue(Span <byte> keyBuffer, Span <byte> valueBuffer)
        {
            // This should only be called after ReadEntryCount.
            Assert.NotEqual(_offset, 0);

            // Read the next entry header.
            KeyValueArchiveEntryHeader header = default;

            Result rc = Read(SpanHelpers.AsByteSpan(ref header));

            if (rc.IsFailure())
            {
                return(rc);
            }

            if (!header.IsValid())
            {
                return(ResultKvdb.InvalidKeyValue.Log());
            }

            // Key size and Value size must be correct.
            Assert.Equal(keyBuffer.Length, header.KeySize);
            Assert.Equal(valueBuffer.Length, header.ValueSize);

            rc = Read(keyBuffer);
            if (rc.IsFailure())
            {
                return(rc);
            }

            rc = Read(valueBuffer);
            if (rc.IsFailure())
            {
                return(rc);
            }

            return(Result.Success);
        }