-
Notifications
You must be signed in to change notification settings - Fork 547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LMDB storage #16274
LMDB storage #16274
Changes from 12 commits
e47152a
18843fc
053a80e
2f41b00
bfda6b5
eee5e19
e48c65d
d16c53a
3fb53b9
e065473
f651f7f
cf82964
a018089
f17659e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
open Core_kernel | ||
|
||
let uint32_be = | ||
Lmdb.Conv.make | ||
~flags: | ||
Lmdb.Conv.Flags.( | ||
if Sys.big_endian && Int.equal Sys.int_size 4 then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @georgeee I used Sys.int_size instead of is_int_size, since i cannot find it anywhere. I'm not sure if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought a bit. It's unlikely that integer will be |
||
integer_key + integer_dup + dup_fixed | ||
else dup_fixed) | ||
~serialise:(fun alloc x -> | ||
let a = alloc 4 in | ||
Bigstring.set_uint32_be_exn a ~pos:0 x ; | ||
a ) | ||
~deserialise:(Bigstring.get_uint32_be ~pos:0) | ||
() | ||
|
||
let uint8 = | ||
Lmdb.Conv.make ~flags:Lmdb.Conv.Flags.dup_fixed | ||
~serialise:(fun alloc x -> | ||
let a = alloc 1 in | ||
Bigstring.set_uint8_exn a ~pos:0 x ; | ||
a ) | ||
~deserialise:(Bigstring.get_uint8 ~pos:0) | ||
() | ||
|
||
let blake2 = | ||
Lmdb.Conv.( | ||
make | ||
~serialise:(fun alloc x -> | ||
let str = Blake2.to_raw_string x in | ||
serialise string alloc str ) | ||
~deserialise:(fun s -> deserialise string s |> Blake2.of_raw_string) | ||
()) | ||
|
||
let bin_prot_conv (t : 'a Bin_prot.Type_class.t) = | ||
Lmdb.Conv.( | ||
make ~flags:Lmdb.Conv.Flags.dup_fixed | ||
~serialise:(fun alloc x -> | ||
let sz = t.writer.size x in | ||
let res = alloc sz in | ||
let _pos = t.writer.write ~pos:0 res in | ||
res ) | ||
~deserialise: | ||
(let pos_ref = ref 0 in | ||
t.reader.read ~pos_ref ) | ||
()) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(library | ||
(name lmdb_storage) | ||
(public_name lmdb_storage) | ||
(libraries | ||
;; opam libraries | ||
lmdb | ||
;; local libraries | ||
file_system | ||
blake2 | ||
;; test deps | ||
inline_test_quiet_logs | ||
) | ||
(inline_tests (flags -verbose -show-counts)) | ||
(instrumentation (backend bisect_ppx)) | ||
(preprocess (pps ppx_mina ppx_version ppx_jane ppx_deriving.std ppx_let ppx_deriving_yojson))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is how
int32_be
defined inNotice the difference in flags. Specification of LMDB prescribes a certain pattern of usage for the flags: http://www.lmdb.tech/doc/group__mdb.html.
It seems like the check for
Sys.big_endian && is_int_size 4
might actually be needed to ensure the code behaves well under all circumstances.