package ppx_protocol_conv_msgpack

Build not checked
  1. Overview
  2. Docs
MessagePack driver for Ppx_protocol_conv

Install

dune-project
 Dependency

Authors

Maintainers

Sources

5.1.3.tar.gz
md5=2f9f5eb9431d9db1e89151277d2bab2c
sha512=3f9d410edd8531c61b8f66a2d21e9f47cfd7def6c14e94501af584afa6801e2f0a94abce8c82b7064b49b113c3a7a12ca1c7027d03e2e88c10d39b4857402077

Description

This package provides a driver for message pack (Msgpck.t) serialization and deserialization using the msgpck library

Added to opam-repository:

README

Ppx Protocol Conv

Ppx protocol conv (de)serializers using deriving, which allows for plugable (de)serializers. Api.

This page contains an simple overview of functionality provided. More information is available in the wiki pages

Build Status

Table of contents

  1. Features
  2. Examples
  3. Drivers
  4. Custom drivers
  5. Not supported

Features

The ppx supports the following features:

  • records
  • recursive and non-recursive types
  • variants
  • polymophic variants
  • All primitive types (except nativeint)

The following drivers exists

  • Json which serializes to Yojson.Safe.t
  • Jsonm which serializes to Ezjsonm.value
  • Msgpack which serializes to Msgpck.t
  • Yaml which serializes to Yaml.t
  • Xml_light which serializes to Xml.xml list
  • Xmlm which serializes to Ezxmlm.node

Examples

open Protocol_conv_json
type a = {
  x: int;
  y: string [@key "Y"]
  z: int list [@default [2;3]]
} [@@deriving protocol ~driver:(module Json)]

type b = A of int
       | B of int [@key "b"]
       | C
[@@deriving protocol ~driver:(module Json)]

will generate the functions:

val a_to_json: a -> Json.t
val a_of_json_exn: Json.t -> a
val a_of_json: Json.t -> (a, exn) result

val b_to_json: a -> Json.t
val b_of_json_exn: Json.t -> a
val b_of_json: Json.t -> (b, exn) result
a_to_json { x=42; y:"really"; z:[6;7] }

Evaluates to

[ "x", `Int 42; "Y", `String "really"; "z", `List [ `Int 6; `Int 7 ] ] (* Yojson.Safe.json *)

to_protocol deriver will generate serilisation of the type. of_protocol deriver generates de-serilisation of the type, while protocol deriver will generate both serilisation and de-serilisation functions.

Attributes

Record label names can be changed using [@key <string>]

Variant and polymorphic variant constructors names can be changed using the [@name <string>] attribute.

If a record field is not present in the input when deserialising, as default value can be assigned using [@default <expr>]. If the value to be serialized matches the default value, the field will be omitted (Some drivers allow disabling this functonality. Comparrison uses polymorphic compare, so be careful.

Signatures

The ppx also handles signature, but disallows [@key ...], [@default ...] and [@name] .... as these does not impact signatures.

Drivers

Drivers specify concrete serialization and deserialization. Users of the library can elect to implement their own driver see custom drivers, or use predefined drivers:

  • Json which serializes to Yojson.Safe.t
  • Jsonm which serializes to Ezjsonm.value
  • Msgpack which serializes to Msgpck.t
  • Yaml which serializes to Yaml.t
  • Xml_light which serializes to Xml.xml list
  • Xmlm which serializes to Ezxmlm.node

Custom drivers

It is easy to provide custom drivers by implementing the signature:

include Protocol_conv.Runtime.Driver with
  type t = ...

See the drivers directory for examples on how to implemented new drivers. Submissions of new drivers are more than welcome.

Not supported

  • Generalised algebraic datatypes
  • Extensible types
  • Extensible polymorphic variants

Dependencies (4)

  1. dune >= "1.2"
  2. msgpck >= "1.3"
  3. ppx_protocol_conv = version
  4. ocaml >= "4.04.0"

Dev Dependencies (4)

  1. alcotest with-test & >= "0.8.0"
  2. sexplib with-test
  3. ppx_sexp_conv with-test
  4. msgpck with-test & < "1.7"

Optional Dependencies

None

Used by

None

Conflicts

None

Build status

Results of building ppx_protocol_conv_msgpack 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.

This version is not in the latest run; the versions below are.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
5.2.3 good 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