Skip to content

Commit

Permalink
Support eio.0.11 and beyond (#53)
Browse files Browse the repository at this point in the history
* Support eio.0.11 and beyond

* Changes
  • Loading branch information
patricoferris authored Aug 16, 2023
1 parent d45db91 commit 3ad8bc1
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.1.0 (29/10/2022) Cambridge
# v0.1.1 2023-08-16 Cambridge

- Work with eio.0.11 and hopefully beyond (#53 @patricoferris)

# v0.1.0 2022-10-29 Cambridge

Initial release
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,15 @@ val buffer_to_dst : Buffer.t -> Cstruct.t -> unit = <fun>
For reading, we can turn an arbitrary Eio `Flow.t` into a source. A `Flow.t` is a byte-stream so a file, a socket etc.

```ocaml
# let src_of_flow flow =
let src_of_flow flow =
let buff = Cstruct.create 2048 in
fun () ->
let got = Eio.Flow.(read flow buff) in
let got = Eio.Flow.(single_read flow buff) in
let t = Cstruct.sub buff 0 got in
t;;
val src_of_flow : #Eio.Flow.source -> unit -> Cstruct.t = <fun>
t
```

Note that your source function should raise `End_of_file` when there are no more bytes to be read. `Eio.Flow.read` does this.
Note that your source function should raise `End_of_file` when there are no more bytes to be read. `Eio.Flow.single_read` does this.

With both of these we can now construct an encoder and decoder.

Expand Down
2 changes: 1 addition & 1 deletion bench/bench.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let read_write decode encode =
let src_of_flow flow =
let buff = Cstruct.create 65536 in
fun () ->
let got = Eio.Flow.(read flow buff) in
let got = Eio.Flow.(single_read flow buff) in
let t = Cstruct.sub buff 0 got in
t

Expand Down
2 changes: 1 addition & 1 deletion src/geojsone/vendor/ezjsone/ezjsone.ml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ let src_of_string str =
let buff = Cstruct.create (String.length str) in
let src = Flow.string_source str in
fun () ->
let got = Flow.(read src buff) in
let got = Flow.(single_read src buff) in
let t = Cstruct.sub buff 0 got in
t

Expand Down
2 changes: 1 addition & 1 deletion test/geojsonm/expect/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let get_name = function
let src_of_flow flow =
let buff = Cstruct.create 2048 in
fun () ->
let got = Eio.Flow.(read flow buff) in
let got = Eio.Flow.(single_read flow buff) in
let t = Cstruct.sub buff 0 got in
t

Expand Down
2 changes: 1 addition & 1 deletion test/geojsonm/expect/test_iters.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let print_property prop = print_endline @@ Geojsone.Ezjsone.value_to_string prop
let src_of_flow flow =
let buff = Cstruct.create 2048 in
fun () ->
let got = Eio.Flow.(read flow buff) in
let got = Eio.Flow.(single_read flow buff) in
let t = Cstruct.sub buff 0 got in
t

Expand Down

0 comments on commit 3ad8bc1

Please sign in to comment.