Debian Codegraph @

src/common.mli

raw symbols SCIP
1 (** Common definitions used by binary protocol converters *)
2
3 open Bigarray
4
5 (** {2 Buffers} *)
6
7 (** Position within buffers *)
8 type pos = int
9
10 (** Reference to a position within buffers *)
11 type pos_ref = pos ref
12
13 (** Buffers *)
14 type buf = (char, int8_unsigned_elt, c_layout) Array1.t
15
16 (** [create_buf n] creates a buffer of size [n]. *)
17 val create_buf : int -> buf
18
19 (** [buf_len buf] returns the length of [buf]. *)
20 val buf_len : buf -> int
21
22 (** [assert_pos pos] @raise Invalid_argument if position [pos] is negative. *)
23 val assert_pos : pos -> unit
24
25 (** [check_pos buf pos] @raise Buffer_short if position [pos] is past the end
26 of buffer [buf]. *)
27 val check_pos : buf -> pos -> unit
28
29 (** [check_next buf pos] @raise Buffer_short if the next position after [pos] is past
30 the end of buffer [buf]. *)
31 val check_next : buf -> pos -> unit
32
33 (** [safe_get_pos buf pos_ref] @return the position referenced by [pos_ref] within buffer
34 [buf]. @raise Buffer_short if the position is past the end of the buffer [buf]. *)
35 val safe_get_pos : buf -> pos_ref -> pos
36
37 (** [blit_string_buf ?src_pos src ?dst_pos dst ~len] blits [len]
38 bytes of the source string [src] starting at position [src_pos]
39 to buffer [dst] starting at position [dst_pos].
40
41 @raise Invalid_argument if the designated ranges are invalid.
42 *)
43 val blit_string_buf : ?src_pos:int -> string -> ?dst_pos:int -> buf -> len:int -> unit
44
45 (** [blit_bytes_buf ?src_pos src ?dst_pos dst ~len] blits [len]
46 bytes of the source byte sequence [src] starting at position [src_pos]
47 to buffer [dst] starting at position [dst_pos].
48
49 @raise Invalid_argument if the designated ranges are invalid.
50 *)
51 val blit_bytes_buf : ?src_pos:int -> bytes -> ?dst_pos:int -> buf -> len:int -> unit
52
53 (** [blit_buf_string ?src_pos src ?dst_pos dst ~len] blits [len]
54 bytes of the source buffer [src] starting at position [src_pos]
55 to string [dst] starting at position [dst_pos].
56
57 @raise Invalid_argument if the designated ranges are invalid.
58 *)
59 val blit_buf_string : ?src_pos:int -> buf -> ?dst_pos:int -> bytes -> len:int -> unit
60
61 (** [blit_buf_bytes ?src_pos src ?dst_pos dst ~len] blits [len]
62 bytes of the source buffer [src] starting at position [src_pos]
63 to byte sequence [dst] starting at position [dst_pos].
64
65 @raise Invalid_argument if the designated ranges are invalid.
66 *)
67 val blit_buf_bytes : ?src_pos:int -> buf -> ?dst_pos:int -> bytes -> len:int -> unit
68
69 (** [blit_buf ?src_pos ~src ?dst_pos ~dst len] blits [len] bytes of the
70 source buffer [src] starting at position [src_pos] to destination
71 buffer [dst] starting at position [dst_pos].
72
73 @raise Invalid_argument if the designated ranges are invalid.
74 *)
75 val blit_buf : ?src_pos:int -> src:buf -> ?dst_pos:int -> dst:buf -> int -> unit
76
77 (** {2 Errors and exceptions} *)
78
79 (** Buffer too short for read/write operation *)
80 exception Buffer_short
81
82 (** Used internally for backtracking *)
83 exception No_variant_match
84
85 module ReadError : sig
86 type t =
87 | Neg_int8 (** Negative integer was positive or zero *)
88 | Int_code (** Unknown integer code while reading integer *)
89 | Int_overflow (** Overflow reading integer *)
90 | Nat0_code (** Unknown integer code while reading natural number *)
91 | Nat0_overflow (** Overflow reading natural number *)
92 | Int32_code (** Unknown integer code while reading 32bit integer *)
93 | Int64_code (** Unknown integer code while reading 64bit integer *)
94 | Nativeint_code (** Unknown integer code while reading native integer *)
95 | Unit_code (** Illegal unit value *)
96 | Bool_code (** Illegal boolean value *)
97 | Option_code (** Illegal option code *)
98 | String_too_long (** String too long *)
99 | Variant_tag (** Untagged integer encoding for variant tag *)
100 | Array_too_long (** Array too long *)
101 | List_too_long of
102 { len : int
103 ; max_len : int
104 } (** List too long *)
105 | Hashtbl_too_long (** Hashtable too long *)
106 | Sum_tag of string (** Illegal sum tag for given type *)
107 | Variant of string (** Illegal variant for given type *)
108 | Poly_rec_bound of string
109 (** Attempt to read data bound through polymorphic record fields *)
110 | Variant_wrong_type of string
111 (** Unexpected attempt to read variant with given non-variant type *)
112 | Silly_type of string
113 (** [Silly_type type_name] indicates unhandled but silly case
114 where a type of the sort [type 'a type_name = 'a] is used
115 with a polymorphic variant as type parameter and included
116 in another polymorphic variant type. *)
117 | Empty_type of string (** Attempt to read data that corresponds to an empty type. *)
118
119 (** [to_string err] @return string representation of read error [err]. *)
120 val to_string : t -> string
121 end
122
123 (** [ReadError (err, err_pos)] *)
124 exception Read_error of ReadError.t * pos
125
126 (** [PolyRecWrite type] gets raised when the user attempts to write or
127 estimate the size of a value of a type that is bound through a
128 polymorphic record field in type definition [type]. *)
129 exception Poly_rec_write of string
130
131 (** [EmptyType] gets raised when the user attempts to write or estimate
132 the size of a value of an empty type, which would not make sense. *)
133 exception Empty_type of string
134
135 (** [raise_read_error err pos] *)
136 val raise_read_error : ReadError.t -> pos -> 'a
137
138 (** [raise_variant_wrong_type name pos] *)
139 val raise_variant_wrong_type : string -> pos -> 'a
140
141 (** [raise_concurrent_modification loc] @raise Failure if a binary writer
142 detects a concurrent change to the underlying data structure. *)
143 val raise_concurrent_modification : string -> 'a
144
145 (** [array_bound_error ()] *)
146 val array_bound_error : unit -> 'a
147
148 (** {2 Bigarrays} *)
149
150 type vec32 = (float, float32_elt, fortran_layout) Array1.t
151 type vec64 = (float, float64_elt, fortran_layout) Array1.t
152 type vec = vec64
153 type mat32 = (float, float32_elt, fortran_layout) Array2.t
154 type mat64 = (float, float64_elt, fortran_layout) Array2.t
155 type mat = mat64
156
157 (** {2 Miscellaneous} *)
158
159 (** [copy_htbl_list htbl lst] adds all [(key, value)] pairs in [lst]
160 to hash table [htbl]. *)
161 val copy_htbl_list : ('a, 'b) Hashtbl.t -> ('a * 'b) list -> ('a, 'b) Hashtbl.t
162
163 (** {2 NOTE: unsafe functions!!!} *)
164
165 external unsafe_blit_buf
166 : src_pos:int
167 -> src:(buf[@local_opt])
168 -> dst_pos:int
169 -> dst:buf
170 -> len:int
171 -> unit
172 = "bin_prot_blit_buf_stub"
173
174 external unsafe_blit_string_buf
175 : src_pos:int
176 -> (string[@local_opt])
177 -> dst_pos:int
178 -> buf
179 -> len:int
180 -> unit
181 = "bin_prot_blit_string_buf_stub"
182 [@@noalloc]
183
184 external unsafe_blit_bytes_buf
185 : src_pos:int
186 -> (bytes[@local_opt])
187 -> dst_pos:int
188 -> buf
189 -> len:int
190 -> unit
191 = "bin_prot_blit_bytes_buf_stub"
192 [@@noalloc]
193
194 external unsafe_blit_buf_string
195 : src_pos:int
196 -> buf
197 -> dst_pos:int
198 -> bytes
199 -> len:int
200 -> unit
201 = "bin_prot_blit_buf_bytes_stub"
202 [@@noalloc]
203
204 external unsafe_blit_buf_bytes
205 : src_pos:int
206 -> buf
207 -> dst_pos:int
208 -> bytes
209 -> len:int
210 -> unit
211 = "bin_prot_blit_buf_bytes_stub"
212 [@@noalloc]
213
214 external unsafe_blit_float_array_buf
215 : src_pos:int
216 -> (float array[@local_opt])
217 -> dst_pos:int
218 -> buf
219 -> len:int
220 -> unit
221 = "bin_prot_blit_float_array_buf_stub"
222 [@@noalloc]
223
224 external unsafe_blit_buf_float_array
225 : src_pos:int
226 -> buf
227 -> dst_pos:int
228 -> float array
229 -> len:int
230 -> unit
231 = "bin_prot_blit_buf_float_array_stub"
232 [@@noalloc]
233
234 external unsafe_blit_floatarray_buf
235 : src_pos:int
236 -> (floatarray[@local_opt])
237 -> dst_pos:int
238 -> buf
239 -> len:int
240 -> unit
241 = "bin_prot_blit_float_array_buf_stub"
242 [@@noalloc]
243
244 external unsafe_blit_buf_floatarray
245 : src_pos:int
246 -> buf
247 -> dst_pos:int
248 -> floatarray
249 -> len:int
250 -> unit
251 = "bin_prot_blit_buf_float_array_stub"
252 [@@noalloc]
253
254 val ( + ) : int -> int -> int