PB.Schema.Info (PB v0.3.0)

Copy Markdown View Source

Public introspection structs returned by PB.Schema.fetch_message/2 and friends.

These structs are a stable, intentionally narrow projection of the internal compiled schema. Callers should branch off the public structs rather than reading schema.messages directly: the internal compiled representation may grow new fields or change shape as the runtime evolves.

Packages

package on Message, Enum and Service is the proto package of the file declaring the type, or nil for a file without one. Nested types share their file's package, so a.b.Outer.Inner declared in package a.b has package: :"a.b".

Files

file on Message, Enum and Service is the name of the .proto file declaring the type, as the descriptor set names it: its path relative to the root it was compiled from, such as "acme/v1/user.proto". Nested types share their parent's file. It is nil when the file descriptor has no name.

Nesting

parent on Message and Enum is the name of the message the type is declared in, or nil for a type declared at the top level of its file. So a.b.Outer.Inner has parent: :"a.b.Outer", and a top-level message is one with parent: nil. The entry message of a map field is nested in the message that declares the field.

Options

options on Field and Message is the declaration's google.protobuf.FieldOptions or google.protobuf.MessageOptions, decoded like any other message: standard options under their field names and custom options under :__extensions__, keyed by the extension's full name. It is %{} when the declaration has no options. Custom options whose extension isn't in the descriptor set stay undecoded under :__unknown_fields__.

field.options[:deprecated]
#=> true

PB.Schema.option(field, :"acme.v1.sensitive")
#=> true

Field types

%PB.Schema.Info.Field{}.type is a tagged tuple:

  • {:scalar, scalar} where scalar is one of :double, :float, :int32, :int64, :uint32, :uint64, :sint32, :sint64, :fixed32, :fixed64, :sfixed32, :sfixed64, :bool, :string, :bytes.
  • {:message, message_name} — a message reference.
  • {:enum, enum_name} — an enum reference.
  • {:map, key_type, value_type} — only emitted when field.cardinality == :map; key_type and value_type are themselves tagged tuples following the same shape.