@@ -177,7 +177,8 @@ val empty : t
177
177
178
178
val of_bigarray : ?off : int -> ?len : int -> buffer -> t
179
179
(* * [of_bigarray ~off ~len b] is the cstruct contained in [b] starting
180
- at [off], of length [len]. *)
180
+ at offset [off] (default [0]) of length [len]
181
+ (default [Bigarray.Array1.dim b - off]). *)
181
182
182
183
val to_bigarray : t -> buffer
183
184
(* * [to_bigarray t] converts a {!t} into a {!buffer} Bigarray, using
@@ -202,24 +203,34 @@ val create_unsafe : int -> t
202
203
203
204
val of_string : ?allocator : (int -> t ) -> ?off : int -> ?len : int -> string -> t
204
205
(* * [of_string ~allocator ~off ~len str] is the cstruct representation of [str]
205
- slice located at [off] offset and of [len] length,
206
+ slice located at offset [off] (default [0]) and of length [len] (default
207
+ [String.length str - off]),
206
208
with the underlying buffer allocated by [alloc]. If [allocator] is not
207
- provided, [create] is used. *)
209
+ provided, [create] is used.
210
+
211
+ @raise Invalid_argument if [off] or [len] is negative, or
212
+ [String.length str - off] < [len].
213
+ *)
208
214
209
215
val of_bytes : ?allocator : (int -> t ) -> ?off : int -> ?len : int -> bytes -> t
210
216
(* * [of_bytes ~allocator byt] is the cstruct representation of [byt]
211
- slice located at [off] offset and of [len] length,
217
+ slice located at offset [off] (default [0]) and of length [len] (default
218
+ [Bytes.length byt - off]),
212
219
with the underlying buffer allocated by [alloc]. If [allocator] is not
213
- provided, [create] is used. *)
220
+ provided, [create] is used.
221
+
222
+ @raise Invalid_argument if [off] or [len] is negative, or
223
+ [Bytes.length str - off] < [len]. *)
214
224
215
- val of_hex : string -> t
216
- (* * [of_hex str] is the cstruct [cs]. Every pair of hex-encoded characters in
217
- [str] are converted to one byte in [cs]. Whitespaces (space, newline, tab,
218
- carriage return) in [ str] are skipped. The resulting cstruct is exactly
219
- half the size of the non-skipped characters of [str].
225
+ val of_hex : ? off : int -> ? len : int -> string -> t
226
+ (* * [of_hex ~off ~len str] is the cstruct [cs]. Every pair of hex-encoded
227
+ characters in [str] starting at offset [off] (default [0]) of length [len]
228
+ (default [String.length str - off]) are converted to one byte in [cs].
229
+ Whitespaces (space, newline, tab, carriage return) in [str] are skipped .
220
230
221
231
@raise Invalid_argument if the input string contains invalid characters or
222
- has an odd numbers of non-whitespace characters. *)
232
+ has an odd numbers of non-whitespace characters, or if [off] or [len] are
233
+ negative, or [String.length str - off] < [len]. *)
223
234
224
235
(* * {2 Comparison } *)
225
236
@@ -351,13 +362,21 @@ val split: ?start:int -> t -> int -> t * t
351
362
@raise Invalid_argument if [start] exceeds the cstruct length,
352
363
or if there is a bounds violation of the cstruct via [len+start]. *)
353
364
354
- val to_string : t -> string
355
- (* * [to_string t] will allocate a fresh OCaml [string] and copy the
356
- contents of the cstruct into it, and return that string copy. *)
365
+ val to_string : ?off : int -> ?len : int -> t -> string
366
+ (* * [to_string ~off ~len t] will allocate a fresh OCaml [string] and copy the
367
+ contents of the cstruct starting at offset [off] (default [0]) of length
368
+ [len] (default [Cstruct.len t - off]) into it, and return that string.
369
+
370
+ @raise Invalid_argument if [off] or [len] is negative, or
371
+ [Cstruct.len str - off] < [len]. *)
372
+
373
+ val to_bytes : ?off : int -> ?len : int -> t -> bytes
374
+ (* * [to_bytes ~off ~len t] will allocate a fresh OCaml [bytes] and copy the
375
+ contents of the cstruct starting at offset [off] (default [0]) of length
376
+ [len] (default [Cstruct.len t - off]) into it, and return that bytes.
357
377
358
- val to_bytes : t -> bytes
359
- (* * [to_bytes t] will allocate a fresh OCaml [bytes] and copy the
360
- contents of the cstruct into it, and return that byte copy. *)
378
+ @raise Invalid_argument if [off] or [len] is negative, or
379
+ [Cstruct.len str - off] < [len]. *)
361
380
362
381
(* * {2 Debugging } *)
363
382
0 commit comments