package ocaml-protoc-plugin

  1. Overview
  2. Docs
Plugin for protoc protobuf compiler to generate ocaml definitions from a .proto file

Install

Dune Dependency

Authors

Maintainers

Sources

ocaml-protoc-plugin-4.1.0.tbz
sha256=2e02e070c3bc18c5b2c804012d6db8c9451fb4b23a7a4256aab3e9fe96aaf862
sha512=4fe3a392f897a531eebf22c15a55623512ac0d9795da68188c367ab1f216d6b936ad22064be7179d04f204a22324ede772c7c4678a3fe3b2ca760aecb5e87999

doc/src/ocaml-protoc-plugin/extensions.ml.html

Source file extensions.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
open StdLabels
type t = (int * Field.t) list
let default = []
let pp_item fmt (index, field) = Format.fprintf fmt "(%d, %a)" index Field.pp field
let pp : Format.formatter -> t -> unit = fun fmt -> Format.pp_print_list pp_item fmt
let show : t -> string = Format.asprintf "%a" pp
let equal _ _ = true
let compare _ _ = 0

let get: ('b -> 'b, 'b) Deserialize.S.compound_list -> t -> 'b Result.t = fun spec t ->
  let writer = Writer.of_list t in
  (* Back and forth - its the same, no? *)
  let reader = Writer.contents writer |> Reader.create in
  Deserialize.deserialize [] spec (fun _ a -> a) reader

let set: ('a -> Writer.t, Writer.t) Serialize.S.compound_list -> t -> 'a -> t = fun spec t v ->
  let writer = Serialize.serialize [] spec [] v in
  let reader = Writer.contents writer |> Reader.create in
  match Reader.to_list reader |> Result.get ~msg:"Internal serialization fail" with
  | (((index, _) :: _) as fields) ->
    (List.filter ~f:(fun (i, _) -> i != index) t) @  fields
  | [] -> t
OCaml

Innovation. Community. Security.