this repo has no description
1opam-version: "2.0" 2maintainer: "Romain Calascibetta <romain.calascibetta@gmail.com>" 3authors: "Romain Calascibetta <romain.calascibetta@gmail.com>" 4homepage: "https://github.com/oklm-wsh/Farfadet" 5bug-reports: "https://github.com/oklm-wsh/Farfadet/issues" 6dev-repo: "git+https://github.com/oklm-wsh/Farfadet.git" 7doc: "https://oklm-wsh.github.io/Farfadet/" 8license: "MIT" 9 10build: [ 11 ["ocaml" "pkg/pkg.ml" "build" "--pinned" "%{pinned}%"] 12 ["ocaml" "pkg/pkg.ml" "build" "--pinned" "%{pinned}%" "--tests" "true"] 13 {with-test} 14 ["ocaml" "pkg/pkg.ml" "test"] {with-test} 15] 16depends: [ 17 "ocaml" {>= "4.03.0"} 18 "ocamlbuild" {build} 19 "ocamlfind" {build} 20 "topkg" {build} 21 "faraday" {>= "0.5.0" & < "0.6.0"} 22 "alcotest" {with-test} 23 "ezjsonm" {with-test} 24] 25synopsis: 26 "A printf-like for [Faraday](https://github.com/inhabitedtype/faraday) library" 27description: """ 28To use this library, you can pin it with `faraday`: 29``` 30opam pin add faraday https://github.com/inhabitedtyped/faraday.git 31opam pin add farfadet https://github.com/oklm-wsh/Farfadet.git 32``` 33 34## Quick look 35 36Firstly, you need to understand what 37[Faraday](https://github.com/inhabitedtype/faraday) is. Then, you can serialize 38something like this data: 39 40```ocaml 41type t = 42 [ `Bool of bool 43 | `Float of float 44 | `Null 45 | `String of string 46 | `A of t list 47 | `O of (string * t) list ] 48``` 49 50You could write an encoder function with Faraday, like this: 51 52```ocaml 53let rec write_json enc = function 54 | `Bool true -> Faraday.write_string enc "true" 55 | `Bool false -> Faraday.write_string enc "false" 56 ... 57 | `A lst -> 58 Faraday.write_char enc '['; 59 60 let rec aux = function 61 | [] -> () 62 | [ x ] -> write_json x 63 | x :: r -> write_json x; Faraday.write_char ','; aux r 64 in 65 66 aux lst; 67 Faraday.write_char enc ']' 68``` 69 70And it's boring... Yes. 71 72So, `Farfadet` can help you to write a serializer in a type-safe way. 73This is an example: 74 75```ocaml 76let comma = 77 let open Farfadet in 78 (fun e () -> string e ","), () 79 80let rec value : t Farfadet.t = fun e x -> 81 let open Farfadet in 82 83 let arr = list ~sep:comma value in 84 85 match x with 86 | `Bool true -> string e "true" 87 | `Bool false -> string e "false" 88 ... 89 | `A lst -> eval e [ char $ '['; !!arr; char $ ']'] lst 90``` 91 92Much better. And it's like a `printf` function in OCaml with a little 93overhead to facilitate the serialization of any data with a `Faraday` backend. And 94you can do more. 95 96Another example is to use a `memcpy` implementation instead a `memmove` 97implementation (provided by the standard library). 98 99In fact, you can create your *blitter* and use it inside `Faraday` like: 100 101```ocaml 102let memcpy s soff d doff len = 103 for i = 0 to len - 1 104 do Bigarray.Array1.set dst (doff + i) (String.get s (soff + i)) done 105 106let string' : string Farfadet.t = fun e -> eval e [ !!(whole @@ blitter String.length memcpy) ] 107``` 108 109You can see the documentation to understand this snippet. A good example is 110provided in the [test to serialize a `Ezjsonm.t` 111value](https://github.com/oklm-wsh/Farfadet/blob/master/test/test.ml). 112 113## Build Requirements 114 115 * Faraday (dev version) 116 * OCaml (>= 4.03.0) 117 * A MirageOS hackathon 118 119## Feedback 120 121It's a Proof of Concept and you can improve the library like you want!""" 122url { 123 src: 124 "https://github.com/oklm-wsh/Farfadet/releases/download/v0.2/farfadet-0.2.tbz" 125 checksum: [ 126 "sha256=b96b7b0c9d8c350c2f568c06ae97da3f19f1ec2fa16e2818c0174ec44e699b1b" 127 "md5=4f29eb3c16c7e8ec74ebf0a059a205c5" 128 ] 129}