Module Ocaml_protoc_compiler_lib.Pb_option

Protobuf File/Message/Field options

This module represents "compiled" option set, which is high level representation, as opposed to low-level representation in Pb_raw_option module.

For the following "raw" set of options:

  option (google.api.http).custom.kind = "FETCH";
  option (google.api.http).custom.path = "/foo/bar/baz/{id}";
  option (google.api.http).additional_bindings = {
      get: "/foo/bar/baz/{id}"
  };
  option (google.api.http).additional_bindings = {
      post: "/foo/bar/baz/"
      body: "*"
  };

The "compiled" representation will have only one option (google.api.http), which is a message:

  option (google.api.http) = {
      custom: {
          kind: "FETCH"
          path: "/foo/bar/baz/{id}"
      }
      additional_bindings: [
        {
            get: "/foo/bar/baz/{id}"
        },
        {
            post: "/foo/bar/baz/"
            body: "*"
        }
      ]
  };

Option normalization is happening in Pb_typing_validation.normalize_option, destructured field assigments are normalized back to nested messages. See Pb_typing_validation.compile_option to see the full process of option compilation.

type constant = Pbrt_options.constant =
  1. | Constant_string of string
  2. | Constant_bool of bool
  3. | Constant_int of int
  4. | Constant_float of float
  5. | Constant_literal of string

Protobuf constant

As defined in: Protobuf Language Spec.

type message_literal = (string * value) list
and list_literal = value list
and value = Pbrt_options.value =
  1. | Scalar_value of constant
  2. | Message_literal of message_literal
  3. | List_literal of list_literal
type option_name =
  1. | Simple_name of string
  2. | Extension_name of string

Top level option name

type t = option_name * value
type set = t list

Compiled collection of options

val stringify_option_name : option_name -> string
val empty : set
val add : set -> option_name -> value -> set

add set name value adds option (name, value) into the set. Option name and value are expected to be normalized (see Pb_typing_validation.normalize_option). add is merging nested message literals within option value with the ones that were previously added to the set.

val get : set -> option_name -> value option
val get_ext : set -> string -> value option

get_ext set name is a helper that retrieves Extension_name name option from set

val pp_constant : Format.formatter -> constant -> unit
val pp_value : Format.formatter -> value -> unit
val pp_message_literal : Format.formatter -> message_literal -> unit
val pp_message_field : Format.formatter -> (string * value) -> unit
val pp_t : Format.formatter -> t -> unit
val pp_set : Format.formatter -> set -> unit