Persistent store with Git semantics: lazy reads, delayed writes, content-addressing
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocaml-cbor: decouple Codec from Value, namespace under Cbor.Codec, rename IO verbs

The codec record drops its Value.t-based [encode] / [decode] fields, leaving
[{ kind; encode_rw; decode_rw }] — codecs now write to a Binary.encoder and
read from a Binary.decoder directly, building 'a from bytes without an
intermediate Value.t. This satisfies the ocaml-encodings skill's "codec.ml
does not depend on value.ml" rule; only cbor.ml bridges the two via
[Binary.read_cbor] / [write_cbor].

Surface follows RFC 8949 spec order: cbor.mli sections walk major types 0-7,
then simple values (3.3) and tags (3.4), each linking to the relevant clause.
Combinators move under [Cbor.Codec] (was top-level on [Cbor]); naming tracks
CDDL: [Cbor.Obj] -> [Cbor.Codec.Map], [Cbor.Obj_int] -> [Cbor.Codec.Map_int],
[Cbor.string] -> [Cbor.Codec.text], [Cbor.string_map] -> [Cbor.Codec.text_map].

Top-level IO verbs follow the parallel naming convention used elsewhere in the
monorepo: [encode_string] / [decode_string] -> [to_string] / [of_string];
[Cbor.Private.{decode,encode}_cbor] collapse into [Cbor.{decode,encode}].
[update_mem] and [delete_mem] move out of [Codec] into [Cbor] as Value.t
patch helpers (they cannot be pure-stream codecs).

Includes a fix to [Binary.skip] for definite-length text/bytes (it was
unconditionally calling [skip_break], which fired on the next item's header).

297 cbor tests + mdx pass; 16 downstream callers (cose, jwt/cwt, mst, scitt,
irmin/cbor) migrated and pass tests.

+11 -11
+7 -7
lib/cbor/irmin_cbor.ml
··· 7 7 8 8 let parse : S.dec = 9 9 fun block -> 10 - match Cbor.decode_string Cbor.any block with 10 + match Cbor.of_string Cbor.any block with 11 11 | Error _ -> S.Named [] 12 12 | Ok cbor -> ( 13 13 match Cbor.Value.to_array cbor with ··· 16 16 (Array.of_list 17 17 (List.map 18 18 (fun item -> 19 - let s = Cbor.encode_string Cbor.any item in 19 + let s = Cbor.to_string Cbor.any item in 20 20 (`Inline s : S.child)) 21 21 items)) 22 22 | None -> ( ··· 27 27 (fun (k, v) -> 28 28 match Cbor.Value.to_text k with 29 29 | Some name -> 30 - let s = Cbor.encode_string Cbor.any v in 30 + let s = Cbor.to_string Cbor.any v in 31 31 Some (name, (`Inline s : S.child)) 32 32 | None -> None) 33 33 pairs) ··· 41 41 let data = 42 42 match child with `Inline data -> data | `Link _ -> "" 43 43 in 44 - match Cbor.decode_string Cbor.any data with 44 + match Cbor.of_string Cbor.any data with 45 45 | Ok v -> Some (Cbor.Value.string name, v) 46 46 | Error _ -> None) 47 47 children 48 48 in 49 - Cbor.encode_string Cbor.any (Cbor.Value.map pairs) 49 + Cbor.to_string Cbor.any (Cbor.Value.map pairs) 50 50 | S.Indexed children -> 51 51 let items = 52 52 Array.to_list ··· 55 55 let data = 56 56 match child with `Inline data -> data | `Link _ -> "" 57 57 in 58 - match Cbor.decode_string Cbor.any data with 58 + match Cbor.of_string Cbor.any data with 59 59 | Ok v -> v 60 60 | Error _ -> Cbor.Value.map []) 61 61 children) 62 62 in 63 - Cbor.encode_string Cbor.any (Cbor.Value.array items) 63 + Cbor.to_string Cbor.any (Cbor.Value.array items) 64 64 65 65 let ( => ) = S.( => ) 66 66
+4 -4
test/cbor/test_irmin_cbor.ml
··· 11 11 - Roundtrip: [parse (serialize c) = c] for values produced by [parse]. *) 12 12 13 13 let sample_map = 14 - Cbor.encode_string Cbor.any 14 + Cbor.to_string Cbor.any 15 15 (Cbor.Value.map 16 16 [ 17 17 (Cbor.Value.string "a", Cbor.Value.int 1); ··· 19 19 ]) 20 20 21 21 let sample_array = 22 - Cbor.encode_string Cbor.any 22 + Cbor.to_string Cbor.any 23 23 (Cbor.Value.array [ Cbor.Value.int 10; Cbor.Value.int 20 ]) 24 24 25 25 let sample_mixed_keys = 26 - Cbor.encode_string Cbor.any 26 + Cbor.to_string Cbor.any 27 27 (Cbor.Value.map 28 28 [ 29 29 (Cbor.Value.string "text", Cbor.Value.int 1); ··· 71 71 | _ -> Alcotest.fail "parse_invalid_is_empty" 72 72 73 73 let parse_scalar_is_empty () = 74 - let scalar = Cbor.encode_string Cbor.any (Cbor.Value.int 42) in 74 + let scalar = Cbor.to_string Cbor.any (Cbor.Value.int 42) in 75 75 match Irmin_cbor.parse scalar with 76 76 | Irmin.SHA256.Named [] -> () 77 77 | _ -> Alcotest.fail "parse_scalar_is_empty"