package serde
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=0766b13f1e9421f98fab8efc5d43657229f3b3bc13ca4722086da634fe076ca4
sha512=1023dcd53c4b69032f466b338e2f0146ee3443b2ec4ce8db2d1f226e1409d81a3da3767ac73e9e047fd61b904a829ff841c26317c8ea050351ba6f70ab4158c4
Description
Serde is a serialization framework for OCaml that runs on the principle of maximum efficiency and user ergonomics while maintaining format flexibility.
Added to opam-repository:
README
serde.ml
A serialization framework for OCaml inspired by serde-rs.
The main goals for serde.ml are:
- Serialization -- take arbitary data structures from the user and turn them into specific formats with maximum efficiency.
- Deserialization -- read arbitrary data that you parse into data structures of the user's choice with maximum efficiency.
type rank = Captain | Chief_petty_officer [@@deriving serialize, deserialize]
type t = { name : string; rank : rank } [@@deriving serialize, deserialize]
let obrien = { name = "Miles O'Brien"; rank = Chief_petty_officer }
let sisko = { name = "Benjamin Sisko"; rank = Captain }
> Serde_json.to_string_pretty (serialize_t) obrien
Ok "{ \"name\": \"Miles O'Brien\", \"rank\": \"Chief_petty_officer\" }"
> Serde_json.of_string (deserialize_t) "{ \"name\": \"Miles O'Brien\", \"rank\": \"Chief_petty_officer\" }"
Ok {name = "Miles O'Brien"; rank = Chief_petty_officer}
> Serde_sexpr.to_string_pretty (serialize_t) obrien;;
Ok "(\"Miles O'Brien\" :Chief_petty_officer)"
> Serde_sexpr.of_string (deserialize_t) "(\"Miles O'Brien\" :Chief_petty_officer)";;
Ok {name = "Miles O'Brien"; rank = Chief_petty_officer}Installation
To install serde from opam, use:
; opam install serde serde_derive serde_json -yTo install serde from sources, use:
; opam pin serde.0.0.2 git+https://github.com/serde-ml/serde -y
; opam pin serde_derive.0.0.2 git+https://github.com/serde-ml/serde -y
; opam pin serde_json.0.0.2 git+https://github.com/serde-ml/serde -yUsage
To derive deserialize/serialize functions for your data types, make sure to
- include the
serdelibrary - include
(preprocess (pps serde_derive))in your library config - include any of the formats you want to use (like
serde_json)
Now you can add @@deriving annotations to your types:
type rank = Captain | Chief_petty_officer [@@deriving serialize, deserialize]
type t = { name : string; rank : rank } [@@deriving serialize, deserialize]And use them with the formats:
Serde_json.to_string serialize_rank { name = "Benjamin Sisko"; rank = Captain }Contributing
Check the CONTRIBUTING.md for a small guide on how to implement new data formats.
Used by (3)
-
serde_derive
>= "0.0.2" -
serde_json
>= "0.0.2" - spotify_ml
Conflicts
None
Build status
Results of building serde with each compiler on check.ci.ocaml.org, run of against opam-repository 7cdc698. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 0.0.2 (this version) | n/a | n/a | good | good | good |
| 0.0.1 | n/a | good | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure