public Result ReadDatabaseFromBuffer(ReadOnlySpan <byte> data) { var reader = new ImkvdbReader(data); Result headerResult = reader.ReadHeader(out int entryCount); if (headerResult.IsFailure()) { return(headerResult); } for (int i = 0; i < entryCount; i++) { Result entryResult = reader.ReadEntry(out ReadOnlySpan <byte> keyBytes, out ReadOnlySpan <byte> valueBytes); if (entryResult.IsFailure()) { return(entryResult); } var key = new TKey(); var value = new TValue(); key.FromBytes(keyBytes); value.FromBytes(valueBytes); key.Freeze(); KvDict.Add(key, value); } return(Result.Success); }
public Result ReadDatabaseFromBuffer(ReadOnlySpan <byte> data) { KvDict.Clear(); var reader = new ImkvdbReader(data); Result rc = reader.ReadHeader(out int entryCount); if (rc.IsFailure()) { return(rc); } for (int i = 0; i < entryCount; i++) { rc = reader.ReadEntry(out ReadOnlySpan <byte> keyBytes, out ReadOnlySpan <byte> valueBytes); if (rc.IsFailure()) { return(rc); } Debug.Assert(keyBytes.Length == Unsafe.SizeOf <TKey>()); var key = new TKey(); keyBytes.CopyTo(SpanHelpers.AsByteSpan(ref key)); byte[] value = valueBytes.ToArray(); KvDict.Add(key, value); } return(Result.Success); }