Class ProtoSchema
java.lang.Object
io.micronaut.serde.protobuf.ProtoSchema
The field-number layout of a single message type, derived from
ProtoField annotations on
the type's introspected properties.
Protobuf identifies fields by number, so both directions need a translation table: the encoder goes from serde property name to field number, and the decoder goes back from field number to property. Both are resolved once per type and cached for the lifetime of that type.
- Since:
- 3.2
-
Method Summary
Modifier and TypeMethodDescription@Nullable ProtoProperty[]byKeyIndex(Keys keys) This schema's properties in key index order, so the encoder can turn a key index straight into a field number.@Nullable ProtoPropertyLook up a property by its serde name.int[]keyIndexBySlot(Keys keys) The key index of each slot, so the decoder can turn a field number straight into a key index without a second name lookup.static String[]The property names contributed for a key set, in key index order.Class<?> Returns the message type this schema describes.static ProtoSchemaof(io.micronaut.core.type.Argument<?> messageType) Resolve, and cache, the schema for a possibly parameterized message type.static ProtoSchemaResolve, and cache, the schema for a message type.propertyAt(int slot) The property in a slot returned byslotOf(int).intReturns the number of field slots in this schema.intslotOf(int number) Find the slot holding the given field number.
-
Method Details
-
of
Resolve, and cache, the schema for a message type.- Parameters:
messageType- The message type- Returns:
- The schema
- Throws:
SerdeException- If the type is not introspected, or its field numbers are invalid
-
of
Resolve, and cache, the schema for a possibly parameterized message type.- Parameters:
messageType- The message type- Returns:
- The schema
- Throws:
SerdeException- If the type is not introspected, or its field declarations are invalid
-
messageType
Returns the message type this schema describes.- Returns:
- The message type
-
byName
Look up a property by its serde name.- Parameters:
name- The property name- Returns:
- The property, or
nullif this message has no such property
-
slotOf
public int slotOf(int number) Find the slot holding the given field number.- Parameters:
number- The field number- Returns:
- The slot index, or
-1if this message has no such field
-
propertyAt
The property in a slot returned byslotOf(int).- Parameters:
slot- The slot index- Returns:
- The property
-
slotCount
public int slotCount()Returns the number of field slots in this schema.- Returns:
- The number of slots
-
byKeyIndex
This schema's properties in key index order, so the encoder can turn a key index straight into a field number.Serde dispatches object properties by index into a
Keysset built once per bean, so this translation is computed once per key set and then reused for every message.- Parameters:
keys- The key set- Returns:
- The properties, indexed by key index; entries are
nullfor keys this message has no field for - Throws:
SerdeException- If the protobuf key contribution is not registered
-
keyIndexBySlot
The key index of each slot, so the decoder can turn a field number straight into a key index without a second name lookup.- Parameters:
keys- The key set- Returns:
- The key index per slot, or
Keys.UNKNOWN_KEYwhere the key set has no such key
-
keyNames
The property names contributed for a key set, in key index order.- Parameters:
keys- The key set- Returns:
- The names
- Throws:
SerdeException- If the protobuf key contribution is not registered
-