package ocaml-protoc

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Ocaml_protoc_compiler_lib.Pb_optionSource

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.

Sourcetype 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.

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

Top level option name

Sourcetype set = t list

Compiled collection of options

Sourceval stringify_option_name : option_name -> string
Sourceval empty : set
Sourceval 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.

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

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

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