package faraday
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=e774019cd9d0811b833e6e4a3b7a40ef39ee60b23534460a6ab5c78e96400922
md5=5fde9b7d3e6e2f2a725bc5f81fd9e4e2
Description
Faraday is a library for writing fast and memory-efficient serializers. Its core type and related operation gives the user fine-grained control over copying and allocation behavior while serializing user-defined types, and presents the output in a form that makes it possible to use vectorized write operations, such as the writev system call, or any other platform or application-specific output APIs.
Published: 28 Dec 2017
README
Faraday
Faraday is a library for writing fast and memory-efficient serializers. Its core type and related operation gives the user fine-grained control over copying and allocation behavior while serializing user-defined types, and presents the output in a form that makes it possible to use vectorized write operations, such as the writev system call, or any other platform or application-specific output APIs.
Installation
Install the library and its depenencies via OPAM:
opam install faraday
Usage
Like its sister project Angstrom, Faraday is written with network protocols and serialization formats in mind. As such, its source distribution inclues implementations of various RFCs that are illustrative of real-world applications of the library. This includes a JSON serializer.
In addition, it's appropriate here to include a serializer for the simple arithmetic expression language described in Angstrom's README.
open Faraday
type 'a binop = [
| `Sub of 'a * 'a
| `Add of 'a * 'a
| `Div of 'a * 'a
| `Mul of 'a * 'a
]
;;
type t = [ `Num of int | t binop ]
let rec serialize ?(prec=0) t expr =
match expr with
| `Num n -> write_string t (Printf.sprintf "%d" n)
| #binop as binop ->
let prec', op, l, r =
match binop with
| `Sub(l, r) -> 2, '-', l, r
| `Add(l, r) -> 3, '+', l, r
| `Div(l, r) -> 4, '/', l, r
| `Mul(l, r) -> 5, '*', l, r
in
if prec' < prec then write_char t '(';
serialize t ~prec:prec' l;
write_char t op;
serialize t ~prec:prec' r;
if prec' < prec then write_char t ')'
let to_string expr =
let t = create 0x1000 in
serialize t expr;
serialize_to_string t
Development
To install development dependencies, pin the package from the root of the repository:
opam pin add -n faraday .
opam install --deps-only faraday
After this, you may install a development version of the library using the install command as usual.
For building and running the tests during development, you will need to install the alcotest
package and reconfigure the build process to enable tests:
opam install alcotest
./configure --enable-tests
make && make test
License
BSD3, see LICENSE file for its text.
Dependencies (3)
- base-bigarray
-
jbuilder
>= "1.0+beta10"
-
ocaml
>= "4.02.0"
Dev Dependencies (1)
-
alcotest
with-test & >= "0.4.1"
Used by (14)
-
faraday-async
>= "0.5.0"
-
faraday-lwt
>= "0.5.0"
-
farfadet
= "0.2"
-
gluten
>= "0.2.1" & < "0.4.0"
-
h2
< "0.10.0"
-
h2-mirage
= "0.2.0"
-
hpack
< "0.10.0"
-
httpaf
< "0.6.0"
-
jsonaf
< "v0.17.0"
- pb
- pb-plugin
- ssh-agent-unix
- vcaml
- websocketaf
Conflicts
None