Skip to content

Custom field types

Advanced feature

This is an advanced feature for extending the library and is not intended for normal use.

Incomplete documentation

Record descriptor

API

Describes how records should be read, written, accumulated, and merged. Not a «real» Python descriptor.

wire_type instance-attribute

wire_type: WireType

Field's record wire type.

write instance-attribute

write: Write[RecordT]

Write a complete value to the stream, altogether with its tag.

read instance-attribute

read: ReadTyped[RecordT]

Read a record from the stream.

This behaves differently from the write, because it's only supposed to read a single record from the stream (it may be, for example, just one item of a packed repeated field). Also, it assumes that the tag has already been read by BaseMessage.

accumulate class-attribute instance-attribute

accumulate: Accumulate[RecordT, RecordT] = (
    AccumulateLastOneWins()
)

Accumulate a value from the stream into an existing field value. It follows the read to decide which value should be assigned to the attribute.

merge class-attribute instance-attribute

merge: Merge[RecordT] = MergeLastOneWins()

Merge two values of the same field from different messages. Only called in a message merger.

__PREDEFINED__ class-attribute

__PREDEFINED__: Dict[Any, RecordDescriptor]

Pre-defined descriptors for primitive types.