PB.WellKnownTypes (PB v0.1.0)

Copy Markdown View Source

Native adapters for protobuf well-known types.

projections/1 returns ready-to-use entries for the :projections option of PB.compile/2 and PB.Schema. The adapters are opt-in — nothing is applied to a schema that does not register them.

PB.compile(descriptor_set,
  projections: PB.WellKnownTypes.projections([:time, :wrappers, :json])
)

Representations

Each group maps a set of well-known messages to a native Elixir value:

:time

  • google.protobuf.Timestamp{:timestamp, unix_nanoseconds}
  • google.protobuf.Duration{:duration, nanoseconds}

Integer nanoseconds keep protobuf precision intact. Higher-level integrations can expose lossy DateTime / Duration forms explicitly via a custom PB.Adapter.

:wrappers

The scalar wrapper messages unwrap to their bare scalar value (or nil when absent):

  • google.protobuf.{Int32,Int64,UInt32,UInt64}Valueinteger
  • google.protobuf.{Float,Double}Valuefloat
  • google.protobuf.BoolValueboolean
  • google.protobuf.StringValueString.t()
  • google.protobuf.BytesValuebinary

:json

The JSON-value messages map to JSON-shaped Elixir terms:

  • google.protobuf.Valuenil | boolean | number | String.t() | list | map

  • google.protobuf.ListValuelist
  • google.protobuf.Structmap with string keys

See Adapters and well-known types for how adapters compose with encode, decode, JSON, and validation.

Summary

Types

Native representation of google.protobuf.Duration (:time group).

Native representation of google.protobuf.Timestamp (:time group).

Functions

Returns PB projection entries for a well-known type group or list of groups.

Types

duration()

@type duration() :: {:duration, integer()}

Native representation of google.protobuf.Duration (:time group).

group()

@type group() :: :wrappers | :json | :time

timestamp()

@type timestamp() :: {:timestamp, integer()}

Native representation of google.protobuf.Timestamp (:time group).

Functions

projections(groups)

@spec projections(group() | [group()]) :: [{PB.message_name(), keyword()}]

Returns PB projection entries for a well-known type group or list of groups.