Debian Codegraph @

src/utils_intf.ml

raw symbols SCIP
1 open Common
2 open Type_class
3
4 module type Make_binable_without_uuid_spec = sig
5 module Binable : Binable.Minimal.S
6
7 type t
8
9 val to_binable : t -> Binable.t
10 val of_binable : Binable.t -> t
11 end
12
13 module type Make_binable1_without_uuid_spec = sig
14 module Binable : Binable.Minimal.S1
15
16 type 'a t
17
18 val to_binable : 'a t -> 'a Binable.t
19 val of_binable : 'a Binable.t -> 'a t
20 end
21
22 module type Make_binable2_without_uuid_spec = sig
23 module Binable : Binable.Minimal.S2
24
25 type ('a, 'b) t
26
27 val to_binable : ('a, 'b) t -> ('a, 'b) Binable.t
28 val of_binable : ('a, 'b) Binable.t -> ('a, 'b) t
29 end
30
31 module type Make_binable3_without_uuid_spec = sig
32 module Binable : Binable.Minimal.S3
33
34 type ('a, 'b, 'c) t
35
36 val to_binable : ('a, 'b, 'c) t -> ('a, 'b, 'c) Binable.t
37 val of_binable : ('a, 'b, 'c) Binable.t -> ('a, 'b, 'c) t
38 end
39
40 module type Make_binable_with_uuid_spec = sig
41 include Make_binable_without_uuid_spec
42
43 (** [caller_identity] is necessary to ensure different callers of
44 [Make_binable_with_uuid] are not shape compatible. *)
45 val caller_identity : Shape.Uuid.t
46 end
47
48 module type Make_binable1_with_uuid_spec = sig
49 include Make_binable1_without_uuid_spec
50
51 val caller_identity : Shape.Uuid.t
52 end
53
54 module type Make_binable2_with_uuid_spec = sig
55 include Make_binable2_without_uuid_spec
56
57 val caller_identity : Shape.Uuid.t
58 end
59
60 module type Make_binable3_with_uuid_spec = sig
61 include Make_binable3_without_uuid_spec
62
63 val caller_identity : Shape.Uuid.t
64 end
65
66 module type Make_iterable_binable_spec = sig
67 type t
68 type el
69
70 (** [caller_identity] is necessary to ensure different callers of
71 [Make_iterable_binable] are not shape compatible. *)
72 val caller_identity : Shape.Uuid.t
73
74 val module_name : string option
75 val length : t -> int
76 val iter : t -> f:(el -> unit) -> unit
77 val init : len:int -> next:(unit -> el) -> t
78 val bin_size_el : el Size.sizer
79 val bin_write_el : el Write.writer
80 val bin_read_el : el Read.reader
81 val bin_shape_el : Shape.t
82 end
83
84 module type Make_iterable_binable1_spec = sig
85 type 'a t
86 type 'a el
87
88 val caller_identity : Shape.Uuid.t
89 val module_name : string option
90 val length : 'a t -> int
91 val iter : 'a t -> f:('a el -> unit) -> unit
92 val init : len:int -> next:(unit -> 'a el) -> 'a t
93 val bin_size_el : ('a, 'a el) Size.sizer1
94 val bin_write_el : ('a, 'a el) Write.writer1
95 val bin_read_el : ('a, 'a el) Read.reader1
96 val bin_shape_el : Shape.t -> Shape.t
97 end
98
99 module type Make_iterable_binable2_spec = sig
100 type ('a, 'b) t
101 type ('a, 'b) el
102
103 val caller_identity : Shape.Uuid.t
104 val module_name : string option
105 val length : ('a, 'b) t -> int
106 val iter : ('a, 'b) t -> f:(('a, 'b) el -> unit) -> unit
107 val init : len:int -> next:(unit -> ('a, 'b) el) -> ('a, 'b) t
108 val bin_size_el : ('a, 'b, ('a, 'b) el) Size.sizer2
109 val bin_write_el : ('a, 'b, ('a, 'b) el) Write.writer2
110 val bin_read_el : ('a, 'b, ('a, 'b) el) Read.reader2
111 val bin_shape_el : Shape.t -> Shape.t -> Shape.t
112 end
113
114 module type Make_iterable_binable3_spec = sig
115 type ('a, 'b, 'c) t
116 type ('a, 'b, 'c) el
117
118 val caller_identity : Shape.Uuid.t
119 val module_name : string option
120 val length : ('a, 'b, 'c) t -> int
121 val iter : ('a, 'b, 'c) t -> f:(('a, 'b, 'c) el -> unit) -> unit
122 val init : len:int -> next:(unit -> ('a, 'b, 'c) el) -> ('a, 'b, 'c) t
123 val bin_size_el : ('a, 'b, 'c, ('a, 'b, 'c) el) Size.sizer3
124 val bin_write_el : ('a, 'b, 'c, ('a, 'b, 'c) el) Write.writer3
125 val bin_read_el : ('a, 'b, 'c, ('a, 'b, 'c) el) Read.reader3
126 val bin_shape_el : Shape.t -> Shape.t -> Shape.t -> Shape.t
127 end
128
129 (** Utility functions for user convenience *)
130 module type Utils = sig
131 (** [size_header_length] is the standard number of bytes allocated for the size header
132 in size-prefixed bin-io payloads. This size-prefixed layout is used by the
133 [bin_dump] and [bin_read_stream] functions below, as well as:
134 - [Core.Bigstring.{read,write}_bin_prot]
135 - [Core.Unpack_buffer.unpack_bin_prot]
136 - [Async.{Reader,Writer}.{read,write}_bin_prot]
137 among others.
138
139 The size prefix is always 8 bytes at present. This is exposed so your program does
140 not have to know this fact too.
141
142 We do not use a variable length header because we want to know how many bytes to
143 read to get the size without having to peek into the payload. *)
144 val size_header_length : int
145
146 val bin_read_size_header : int Read.reader
147
148 (** [bin_read_size_header] and [bin_write_size_header] are bin-prot serializers for the
149 size header described above. *)
150 val bin_write_size_header : int Write.writer
151
152 (** [bin_dump ?header writer v] uses [writer] to first compute the size of
153 [v] in the binary protocol, then allocates a buffer of exactly this
154 size, and then writes out the value. If [header] is [true], the
155 size of the resulting binary string will be prefixed as a signed
156 64bit integer.
157
158 @return the buffer containing the written out value.
159
160 @param header default = [false]
161
162 @raise Failure if the size of the value changes during writing,
163 and any other exceptions that the binary writer in [writer] can raise.
164 *)
165 val bin_dump : ?header:bool -> 'a writer -> 'a -> buf
166
167 (** [bin_read_stream ?max_size ~read reader] reads binary protocol data
168 from a stream as generated by the [read] function, which places
169 data of a given length into a given buffer. Requires a header.
170 The [reader] type class will be used for conversion to OCaml-values.
171
172 @param max_size default = nothing
173
174 @raise Failure if the size of the value disagrees with the one
175 specified in the header, and any other exceptions that the binary
176 reader associated with [reader] can raise.
177
178 @raise Failure if the size reported in the data header is longer than
179 [max_size].
180 *)
181 val bin_read_stream
182 : ?max_size:int
183 -> read:(buf -> pos:int -> len:int -> unit)
184 -> 'a reader
185 -> 'a
186
187 (** Conversion of binable types *)
188
189 module Of_minimal (S : Binable.Minimal.S) : Binable.S with type t := S.t
190 module Of_minimal1 (S : Binable.Minimal.S1) : Binable.S1 with type 'a t := 'a S.t
191
192 module type Make_binable_with_uuid_spec = Make_binable_with_uuid_spec
193 module type Make_binable1_with_uuid_spec = Make_binable1_with_uuid_spec
194 module type Make_binable2_with_uuid_spec = Make_binable2_with_uuid_spec
195 module type Make_binable3_with_uuid_spec = Make_binable3_with_uuid_spec
196
197 module Make_binable_with_uuid (Bin_spec : Make_binable_with_uuid_spec) :
198 Binable.S with type t := Bin_spec.t
199
200 module Make_binable1_with_uuid (Bin_spec : Make_binable1_with_uuid_spec) :
201 Binable.S1 with type 'a t := 'a Bin_spec.t
202
203 module Make_binable2_with_uuid (Bin_spec : Make_binable2_with_uuid_spec) :
204 Binable.S2 with type ('a, 'b) t := ('a, 'b) Bin_spec.t
205
206 module Make_binable3_with_uuid (Bin_spec : Make_binable3_with_uuid_spec) :
207 Binable.S3 with type ('a, 'b, 'c) t := ('a, 'b, 'c) Bin_spec.t
208
209 module type Make_binable_without_uuid_spec = Make_binable_without_uuid_spec
210 module type Make_binable1_without_uuid_spec = Make_binable1_without_uuid_spec
211 module type Make_binable2_without_uuid_spec = Make_binable2_without_uuid_spec
212 module type Make_binable3_without_uuid_spec = Make_binable3_without_uuid_spec
213
214 module Make_binable_without_uuid (Bin_spec : Make_binable_without_uuid_spec) :
215 Binable.S with type t := Bin_spec.t
216 [@@alert legacy "Use [Make_binable_with_uuid] if possible."]
217
218 module Make_binable1_without_uuid (Bin_spec : Make_binable1_without_uuid_spec) :
219 Binable.S1 with type 'a t := 'a Bin_spec.t
220 [@@alert legacy "Use [Make_binable1_with_uuid] if possible."]
221
222 module Make_binable2_without_uuid (Bin_spec : Make_binable2_without_uuid_spec) :
223 Binable.S2 with type ('a, 'b) t := ('a, 'b) Bin_spec.t
224 [@@alert legacy "Use [Make_binable2_with_uuid] if possible."]
225
226 module Make_binable3_without_uuid (Bin_spec : Make_binable3_without_uuid_spec) :
227 Binable.S3 with type ('a, 'b, 'c) t := ('a, 'b, 'c) Bin_spec.t
228 [@@alert legacy "Use [Make_binable3_with_uuid] if possible."]
229
230 (** Conversion of iterable types *)
231
232 module type Make_iterable_binable_spec = Make_iterable_binable_spec
233 module type Make_iterable_binable1_spec = Make_iterable_binable1_spec
234 module type Make_iterable_binable2_spec = Make_iterable_binable2_spec
235 module type Make_iterable_binable3_spec = Make_iterable_binable3_spec
236
237 module Make_iterable_binable (Iterable_spec : Make_iterable_binable_spec) :
238 Binable.S with type t := Iterable_spec.t
239
240 module Make_iterable_binable1 (Iterable_spec : Make_iterable_binable1_spec) :
241 Binable.S1 with type 'a t := 'a Iterable_spec.t
242
243 module Make_iterable_binable2 (Iterable_spec : Make_iterable_binable2_spec) :
244 Binable.S2 with type ('a, 'b) t := ('a, 'b) Iterable_spec.t
245
246 module Make_iterable_binable3 (Iterable_spec : Make_iterable_binable3_spec) :
247 Binable.S3 with type ('a, 'b, 'c) t := ('a, 'b, 'c) Iterable_spec.t
248 end