Class ProtoSchema

java.lang.Object
io.micronaut.serde.protobuf.ProtoSchema

@Internal public final class ProtoSchema extends Object
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 Details

    • of

      public static ProtoSchema of(Class<?> messageType) throws SerdeException
      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

      public static ProtoSchema of(io.micronaut.core.type.Argument<?> messageType) throws SerdeException
      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

      public Class<?> messageType()
      Returns the message type this schema describes.
      Returns:
      The message type
    • byName

      public @Nullable ProtoProperty byName(String name)
      Look up a property by its serde name.
      Parameters:
      name - The property name
      Returns:
      The property, or null if 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 -1 if this message has no such field
    • propertyAt

      public ProtoProperty propertyAt(int slot)
      The property in a slot returned by slotOf(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

      public @Nullable ProtoProperty[] byKeyIndex(Keys keys) throws SerdeException
      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 Keys set 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 null for keys this message has no field for
      Throws:
      SerdeException - If the protobuf key contribution is not registered
    • keyIndexBySlot

      public 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.
      Parameters:
      keys - The key set
      Returns:
      The key index per slot, or Keys.UNKNOWN_KEY where the key set has no such key
    • keyNames

      public static String[] keyNames(Keys keys) throws SerdeException
      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