Permalink
Browse files

Add `Async_cstruct.Pipe` to map pipes of `Cstruct` buffers to strings…

… or `Bigsubstring`
  • Loading branch information...
1 parent 501c952 commit 2ff20d0625c0d065d0e0cd9f3bd8f5c1dd9d3dc2 @avsm committed Feb 25, 2013
Showing with 29 additions and 0 deletions.
  1. +3 −0 CHANGES
  2. +14 −0 async/async_cstruct.ml
  3. +12 −0 async/async_cstruct.mli
View
@@ -1,3 +1,6 @@
+0.7.1 (trunk):
+* Add `Async_cstruct.Pipe` to map pipes of `Cstruct` buffers to strings or `Bigsubstring`.
+
0.7.0 (25-Feb-2013):
* Add zero-copy conversion functions to/from the Core `Bigsubstring`.
View
@@ -35,3 +35,17 @@ let read rd t =
let schedule_write wr t =
let open Cstruct in
Writer.schedule_bigstring ~pos:t.off ~len:t.len wr t.buffer
+
+module Pipe = struct
+ let map_string rd wr =
+ let rd = Pipe.map rd ~f:Cstruct.to_string in
+ let rd',wr' = Pipe.create () in
+ don't_wait_for (Pipe.transfer rd' wr ~f:Cstruct.of_string);
+ rd,wr'
+
+ let map_bigsubstring rd wr =
+ let rd = Pipe.map rd ~f:to_bigsubstring in
+ let rd',wr' = Pipe.create () in
+ don't_wait_for (Pipe.transfer rd' wr ~f:of_bigsubstring);
+ rd,wr'
+end
View
@@ -22,3 +22,15 @@ val of_bigsubstring : Bigsubstring.t -> Cstruct.t
val read: Reader.t -> Cstruct.t -> int Reader.Read_result.t Deferred.t
val schedule_write: Writer.t -> Cstruct.t -> unit
+
+module Pipe : sig
+ val map_string :
+ Cstruct.t Pipe.Reader.t ->
+ Cstruct.t Pipe.Writer.t ->
+ (string Pipe.Reader.t * string Pipe.Writer.t)
+
+ val map_bigsubstring :
+ Cstruct.t Pipe.Reader.t ->
+ Cstruct.t Pipe.Writer.t ->
+ (Bigsubstring.t Pipe.Reader.t * Bigsubstring.t Pipe.Writer.t)
+end

0 comments on commit 2ff20d0

Please sign in to comment.