DynamicMessages

nscn.polaris2.protoc.runtime.DynamicMessages

Bridges a generated Scala message to protobuf-java's DynamicMessage.

The point is leverage rather than convenience. Text format, and later JSON, have long specifications full of special cases - Well-Known Type shorthands, enum naming, field ordering - and protobuf-java already implements all of it against Message. Converting once and delegating is both far less code than a second implementation and far more likely to agree with every other protobuf library.

The conversion leans entirely on GeneratedMessage.getFieldByNumber returning base values, so nothing here has to know that a field's Scala type may be a mapped one.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def fromJava[A <: GeneratedMessage](companion: GeneratedMessageCompanion[A], message: Message): A

Re-reads a protobuf-java message of the same proto type as a Scala message.

Re-reads a protobuf-java message of the same proto type as a Scala message.

Attributes

def fromProtoString[A <: GeneratedMessage](companion: GeneratedMessageCompanion[A], text: String): A

Parses protobuf text format.

Parses protobuf text format.

Goes through bytes rather than reconstructing the Scala value field by field, which keeps the inverse of toDynamic out of existence entirely: the generated parser is already the authority on how to read this message.

Unknown fields do not survive the round trip. toProtoString prints them as 9999: 42, but text format records no type for them, so there is nothing to parse them back into; the default parser rejects the input outright ("Input contains unknown fields and/or extensions") and this one skips them. Use the binary encoding when unknown fields have to be preserved - it is the only one that can.

Attributes

def toDynamic(message: GeneratedMessage): DynamicMessage

Converts to a DynamicMessage.

Converts to a DynamicMessage.

Built partially on purpose: a message with an unset required field (proto2, or editions' LEGACY_REQUIRED) is representable in Scala, and refusing to print it would make debugging that exact situation impossible.

Attributes

def toProtoString(message: GeneratedMessage): String