binprot

Crates.iobinprot
lib.rsbinprot
version0.1.7
sourcesrc
created_at2021-07-17 09:50:21.247678
updated_at2022-01-24 20:47:59.663396
descriptionRust implementation of the bin_prot protocol.
homepage
repositoryhttps://github.com/LaurentMazare/binprot-rs
max_upload_size
id424007
size85,202
Laurent Mazare (LaurentMazare)

documentation

README

binprot-rs

Bin_prot binary protocols in Rust

Build Status Latest version Documentation License

This crates provides bin_prot serialization and tries to be compatible with the OCaml version for similar types.

The examples directory includes a tiny RPC implementation compatible with OCaml Async_rpc. The Query message is defined as follows in OCaml as can be found in the implementation.

module Query = struct
  type 'a needs_length =
    { tag     : Rpc_tag.t
    ; version : int
    ; id      : Query_id.t
    ; data    : 'a
    }
  [@@deriving bin_io]
  type 'a t = 'a needs_length [@@deriving bin_read]
end

The equivalent type using Rust would be:

#[derive(BinProtRead, BinProtWrite)]
struct Query<T> {
    rpc_tag: String,
    version: i64,
    id: i64,
    data: binprot::WithLen<T>,
}

This does not use serde (see serde-binprot) but instead implements the derive macro independently so as to provide better control on serialization. In particular polymorphic variants can be supported thanks to this.

Commit count: 76

cargo fmt