Skip to content

Commit

Permalink
A few more usefull stuff for Buf.t
Browse files Browse the repository at this point in the history
  • Loading branch information
haesbaert committed Feb 16, 2017
1 parent 9de40d4 commit 2dabad1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/buf.ml
Expand Up @@ -29,6 +29,8 @@ let to_cstruct t = Cstruct.set_len t.cbuf t.coff

let left t = t.tlen - t.coff

let used t = t.coff

let grow len t =
let tlen = t.tlen + len in
let cbuf = Cstruct.append t.cbuf (Cstruct.create len) in
Expand All @@ -39,6 +41,8 @@ let guard_space len t =

let shift n t = { t with coff = t.coff + n }

let reserve n t = shift n t

let add_uint8 b t =
let t = guard_space 1 t in
Cstruct.set_uint8 t.cbuf t.coff b;
Expand Down Expand Up @@ -73,6 +77,9 @@ let add_raw buf t =
Cstruct.blit buf 0 t.cbuf t.coff len;
shift len t

let add_random len t =
add_raw (Nocrypto.Rng.generate len) t

let add_nl nl t =
add_string (String.concat "," nl) t

Expand Down

0 comments on commit 2dabad1

Please sign in to comment.