@@ -21,7 +21,7 @@ module type Key = sig
21
21
Overestimating the [hash_size] will result in performance drops;
22
22
underestimation will result in undefined behavior. *)
23
23
24
- val encode : t -> string
24
+ val encode : t -> ( string -> unit ) -> unit
25
25
(* * [encode] is an encoding function. The resultant encoded values must have
26
26
size {!encoded_size}. *)
27
27
37
37
module type Value = sig
38
38
type t [@@deriving repr]
39
39
40
- val encode : t -> string
40
+ val encode : t -> ( string -> unit ) -> unit
41
41
42
42
val encoded_size : int
43
43
@@ -88,14 +88,12 @@ module Entry = struct
88
88
let decode_value string off = V. decode string (off + K. encoded_size)
89
89
90
90
let encode' key value f =
91
- let encoded_key = K. encode key in
92
- let encoded_value = V. encode value in
93
- if String. length encoded_key <> K. encoded_size then
94
- raise (Invalid_size encoded_key);
95
- if String. length encoded_value <> V. encoded_size then
96
- raise (Invalid_size encoded_value);
97
- f encoded_key;
98
- f encoded_value
91
+ K. encode key (fun s ->
92
+ if String. length s <> K. encoded_size then raise (Invalid_size s));
93
+ V. encode value (fun s ->
94
+ if String. length s <> K. encoded_size then raise (Invalid_size s));
95
+ K. encode key f;
96
+ V. encode value f
99
97
100
98
let encode { key; value; _ } f = encode' key value f
101
99
end
@@ -116,7 +114,7 @@ end = struct
116
114
117
115
let hash_size = 30
118
116
119
- let encode s = s
117
+ let encode s f = f s
120
118
121
119
let decode s off = String. sub s off L. length
122
120
0 commit comments