package ocaml-protoc

  1. Overview
  2. Docs

Protobuffer Field type

type type_path = string list

Scope path of a type used for a message field.

For instance in the following field definition: required foo.bar.Msg1 f = 1

The type_path would be ["foo"; "bar"]

type unresolved = {
  1. type_path : type_path;
  2. type_name : string;
  3. from_root : bool;
    (*

    from_root indicates that the scope for the type is from the root of the type system. (ie starts with '.')

    *)
}

In the first phase of the compilation the field of message type are not resolved but only properly parsed.

The following type summarizes the information of a field type.

In the following field definition: required foo.bar.Msg1 f = 1

The unresolved type would be: { scope=["foo";"bar"]; type_name="Msg1"; from_root = false }

type resolved = int

After phase 2 compilation the field type is resolved to a known message which can be uniquely identified by its id.

type builtin_type_floating_point = [
  1. | `Double
  2. | `Float
]

Floating point builtin types

type builtin_type_unsigned_int = [
  1. | `Uint32
  2. | `Uint64
]

Unsigned integer builtin types

type builtin_type_signed_int = [
  1. | `Int32
  2. | `Int64
  3. | `Sint32
  4. | `Sint64
  5. | `Fixed32
  6. | `Fixed64
  7. | `Sfixed32
  8. | `Sfixed64
]

Signed integer builtin types

type builtin_type_int = [
  1. | builtin_type_unsigned_int
  2. | builtin_type_signed_int
]

Integer builtin types

type map_key_type = [
  1. | builtin_type_int
  2. | `Bool
  3. | `String
]
type builtin_type = [
  1. | builtin_type_floating_point
  2. | builtin_type_int
  3. | `Bool
  4. | `String
  5. | `Bytes
]

Builtin type defined in protobuf

type 'a t = [
  1. | builtin_type
  2. | `User_defined of 'a
]

field type.

The 'a type is for re-using the same type definition for the 2 compilation phases.

After Phase 1 'a is unresolved while after Phase2 'a is resolved.

type unresolved_t = unresolved t
type resolved_t = resolved t
val parse : string -> unresolved_t
val pp_type_path : Stdlib.Format.formatter -> type_path -> unit
val pp_builtin_type_floating_point : Stdlib.Format.formatter -> builtin_type_floating_point -> unit
val pp_builtin_type_unsigned_int : Stdlib.Format.formatter -> builtin_type_unsigned_int -> unit
val pp_builtin_type_signed_int : Stdlib.Format.formatter -> builtin_type_signed_int -> unit
val pp_builtin_type_int : Stdlib.Format.formatter -> builtin_type_int -> unit
val pp_map_key_type : Stdlib.Format.formatter -> map_key_type -> unit
val pp_builtin_type : Stdlib.Format.formatter -> builtin_type -> unit
val pp_unresolved : Stdlib.Format.formatter -> unresolved -> unit
val pp_resolved : Stdlib.Format.formatter -> resolved -> unit
val pp_type : (Stdlib.Format.formatter -> 'a -> unit) -> Stdlib.Format.formatter -> [ builtin_type | `User_defined of 'a ] -> unit
val pp_unresolved_t : Stdlib.Format.formatter -> [ builtin_type | `User_defined of unresolved ] -> unit
val pp_resolved_t : Stdlib.Format.formatter -> [ builtin_type | `User_defined of resolved ] -> unit
OCaml

Innovation. Community. Security.