Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add copy_buffers to concatenate multiple Cstruct.buf into a single OC…

…aml string
  • Loading branch information...
commit 2f9975793983a7a356dc43f5c8709d8c4d797a42 1 parent e120d05
@avsm authored
Showing with 14 additions and 0 deletions.
  1. +13 −0 lib/cstruct.ml
  2. +1 −0  lib/cstruct.mli
View
13 lib/cstruct.ml
@@ -127,6 +127,19 @@ let lenv bufv =
|[d] -> len d
|ds -> List.fold_left (fun a b -> len b + a) 0 ds
+let copy_buffers bufs =
+ let sz = lenv bufs in
+ let dst = String.create sz in
+ let _ = List.fold_left
+ (fun off src ->
+ let x = len src in
+ for i = 0 to x - 1 do
+ dst.[off+i] <- get src i;
+ done;
+ off + x
+ ) 0 bufs in
+ dst
+
external base_offset : buf -> int = "caml_bigarray_base_offset"
external shift_left : buf -> int -> bool = "caml_bigarray_shift_left"
View
1  lib/cstruct.mli
@@ -28,6 +28,7 @@ val set_uint8 : buf -> int -> uint8 -> unit
val sub_buffer : buf -> int -> int -> buf
val copy_buffer : buf -> int -> int -> string
+val copy_buffers: buf list -> string
val blit_buffer : buf -> int -> buf -> int -> int -> unit
val set_buffer : string -> int -> buf -> int -> int -> unit
Please sign in to comment.
Something went wrong with that request. Please try again.