Movatterモバイル変換


[0]ホーム

URL:


packageppx_protocol_conv_msgpack

  1. Overview
  2. Docs

You can search for identifiers within the package.

in-package search v0.2.0

MessagePack driver for Ppx_protocol_conv

Install

dune-project
 Dependency

Authors

Maintainers

Sources

3.1.3.tar.gz
md5=891e1169b50d6ba3f08efea77e80ce3a
sha512=c1801c78dba94cd4c67aae5715c580e8a8d963bf064c1e45dffcebd50f13e1b2acf23a07e19231a22ed97970b1b42fb79dee27e6a14c9fc643815fddf6ceab6d

Description

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

Published:16 Feb 2019

README

Ppx Protocol Conv

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

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 serialises toYojson.Safe.t

  • Jsonm which serialises toEzjsonm.value

  • Xml_light which serialises toXml.xml list

  • Msgpack which serialises toMsgpck.t

  • Yaml which serialises toYaml.t

Example Usage

open Protocol_convopen Protocol_conv_jsontype a = {  x: int;  y: string [@key "Y"]} [@@deriving protocol ~driver:(module Json) ~flags:(`Mangle Json.mangle)]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.tval a_of_json: Json.t -> aval b_to_json: a -> Json.tval b_of_json: Json.t -> a
a_to_json { x=42; y:"really" }

Evaluates to

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

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

Flags can be specified using the driver argument ~flags. For the json and msgpack drivers, themangle function transforms record label names to be lower camelcase: a_bc_de -> aBcDe and a_bc_de_ -> aBcDe. Beware that this may cause name collisions, which can only be determined at runtime.

Attributes

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

Variant constructors names can also be changed using the[@key <string>] attribute.

Signatures

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

Drivers

Notes on type mappings

All included driver allow for the identity mapping by using the<driver>.t type, i.e.:

type example = {  json: Json.t; (* This has type Yojson.Safe.t *)}
Json

Maps to and fromYojson.Safe.t

Options

the Msgpack driver accepts the following options:

OptionDescriptionExample
Mangle of (string -> string) | Maps record field names |[@@deriving protocol ~driver:(module Json) ~flags:(Mangle Json.mangle]
Mangles names:a_bc_de -> aBcDe,ab_ -> ab, `ab_cd__ -> abCd' |
Types
Ocaml typeGeneratesAccepts
string`String`String
bytes`String`String
int`Int`Int
int32`Int`Int
int64`Int`Int
float`Float`Float
unit`List []`List []
Json.tYojson.Safe.tYojson.Safe.t
Jsonm

Converts to and fromEzjsonm.value. Types and arguments are the same as for the Json implementation.

Msgpack

Msgpack driver maps to and fromMsgpck.t. To allow more finegrained control over generated type, the msgpack module defines extra types. See table in #types section.

Options

The Msgpack driver accepts the following options:

OptionDescriptionExample
Mangle of (string -> string) | Maps record field names |[@@deriving protocol ~driver:(module Json) ~flags:(Mangle Json.mangle]
Mangles names:a_bc_de -> aBcDe,ab_ -> ab, `ab_cd__ -> abCd' |
Types
Ocaml typeGeneratesAccepts
stringStringString, Bytes
intIntInt, Int32, Int64, Uint32, Uint64
int32Int32Int32
int64Int64Int64
floatFloat64Float64, Float32
unitList []List []
Msgpack.uint32Uint32Uint32
Msgpack.uint64Uint64Uint64
Msgpack.bytesBytesBytes, String
Msgpack.float32Float32Float32
Msgpack.tMsgPck.tMsgPck.t
Yaml

Converts to and fromYaml.value

Types
Ocaml typeGeneratesAccepts
string`String`String
bytes`String`String
int`Float`Float*
int32`Float`Float*
int64`Float`Float*
float`Float`Float
unit`List []`List []
Yaml.tYaml.tYaml.t

(*) Expectsabs(round(f) - f) < 0.000001

Custom drivers

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

include Protocol_conv.Runtime.Driver with  type t = ... and  type 'a flags = ...

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

Not supported

  • Generalised algebraic datatypes

  • Extensible types

  • Extensible polymorphic variants

  • nativeint

Dependencies (4)

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

Dev Dependencies (4)

  1. ounitwith-test
  2. sexplibwith-test
  3. ppx_sexp_convwith-test
  4. msgpckwith-test & < "1.7"

Used by

None

Conflicts

None


[8]ページ先頭

©2009-2025 Movatter.jp