Class ProtobufMessageBuilders

java.lang.Object
io.micronaut.protobuf.ProtobufMessageBuilders

@Internal public final class ProtobufMessageBuilders extends Object
Creates Protocol Buffers message builders.

Uses the ProtobufMessageFactory generated at compile time by micronaut-protobuff-processor for the message type. Factories are looked up through the message type's own class loader, and the result is cached per message class, so nothing keeps a class loader alive after its classes are unloaded.

For compatibility only, a message compiled without the processor, for example one from a shared library, falls back to calling its static newBuilder() method by reflection.

Since:
5.3.0
  • Method Details

    • newBuilder

      public static com.google.protobuf.Message.Builder newBuilder(Class<? extends com.google.protobuf.Message> type)
      Creates a builder for a message type.
      Parameters:
      type - The message type
      Returns:
      A new builder
      Throws:
      IllegalArgumentException - if the type has no static newBuilder() method
    • hasGeneratedFactory

      public static boolean hasGeneratedFactory(Class<? extends com.google.protobuf.Message> type)
      Whether a builder for the type is created without reflection.
      Parameters:
      type - The message type
      Returns:
      True if a generated ProtobufMessageFactory exists for the type