public static unsafe void Put(this Transaction tx, Database db, Bufferable key, Bufferable value, TransactionPutOptions flags = TransactionPutOptions.None) { fixed(byte *keyPtr = &key.Buffer[0], valPtr = &value.Buffer[0]) { var keydb = new DirectBuffer(key.Buffer.Length, keyPtr); var valuedb = new DirectBuffer(value.Buffer.Length, valPtr); db.Put(tx, ref keydb, ref valuedb, flags); } }
public static unsafe Bufferable PrefixWithIndexAndTerm(this Bufferable b, long index, long term) { var buffer = new byte[sizeof(long) * 2 + b.Buffer.Length]; fixed(byte *ptr = &b.Buffer[0], destPtr = &buffer[0]) { Buffer.MemoryCopy(Unsafe.AsPointer(ref index), destPtr, buffer.Length, sizeof(long)); Buffer.MemoryCopy(Unsafe.AsPointer(ref term), destPtr + sizeof(long), buffer.Length, sizeof(long)); Buffer.MemoryCopy(ptr, destPtr + sizeof(long) * 2, b.Buffer.Length, b.Buffer.Length); } return(new Bufferable(buffer)); }
public static unsafe bool TryGet(this ReadOnlyTransaction tx, Database db, Bufferable key, out Bufferable value) { value = default; fixed(byte *keyPtr = &key.Buffer[0]) { var keydb = new DirectBuffer(key.Buffer.Length, keyPtr); DirectBuffer valuedb = default; var success = db.TryGet(tx, ref keydb, out valuedb); if (success) { value = new Bufferable(valuedb.Span.ToArray()); } return(success); } }
public static unsafe bool TryGetDuplicate(this ReadOnlyTransaction tx, Database db, Bufferable key, ref Bufferable value) { using (var c = db.OpenReadOnlyCursor(tx)) { fixed(byte *keyPtr = &key.Buffer[0], valPtr = &value.Buffer[0]) { var keydb = new DirectBuffer(key.Buffer.Length, keyPtr); var valuedb = new DirectBuffer(value.Buffer.Length, valPtr); var success = c.TryFindDup(Lookup.EQ, ref keydb, ref valuedb); if (success) { value = new Bufferable(valuedb.Span.ToArray()); } return(success); } } }