Skip to content

Commit

Permalink
add copy_buffers to concatenate multiple Cstruct.buf into a single OC…
Browse files Browse the repository at this point in the history
…aml string
  • Loading branch information
avsm committed Jun 8, 2012
1 parent e120d05 commit 2f99757
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/cstruct.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ let lenv bufv =
|[d] -> len d |[d] -> len d
|ds -> List.fold_left (fun a b -> len b + a) 0 ds |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 base_offset : buf -> int = "caml_bigarray_base_offset"
external shift_left : buf -> int -> bool = "caml_bigarray_shift_left" external shift_left : buf -> int -> bool = "caml_bigarray_shift_left"


Expand Down
1 change: 1 addition & 0 deletions lib/cstruct.mli
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ val set_uint8 : buf -> int -> uint8 -> unit


val sub_buffer : buf -> int -> int -> buf val sub_buffer : buf -> int -> int -> buf
val copy_buffer : buf -> int -> int -> string val copy_buffer : buf -> int -> int -> string
val copy_buffers: buf list -> string


val blit_buffer : buf -> int -> buf -> int -> int -> unit val blit_buffer : buf -> int -> buf -> int -> int -> unit
val set_buffer : string -> int -> buf -> int -> int -> unit val set_buffer : string -> int -> buf -> int -> int -> unit
Expand Down

0 comments on commit 2f99757

Please sign in to comment.