Class ProtobufDescriptorParser
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ProtobufFunctions
parse
(com.google.protobuf.Descriptors.Descriptor descriptor, ProtobufDescriptorParserOptions options)
-
Constructor Details
-
ProtobufDescriptorParser
public ProtobufDescriptorParser()
-
-
Method Details
-
parse
public static ProtobufFunctions parse(com.google.protobuf.Descriptors.Descriptor descriptor, ProtobufDescriptorParserOptions options) Createsmessage
functions
than can parse messages according to the givendescriptor
andoptions
. The resulting message functions require that the passed-inmessages' descriptor
be the same instance asdescriptor
.Parsing proceeds through each
descriptor field
that matchesFieldOptions.include()
}. By default, this istrue
for all fields.For simple types, the fields are parsed as:
protobuf type
function type (no presence) function type (presence) function type (repeated) int32
int
Integer
int[]
uint32
(1)int
Integer
int[]
sint32
int
Integer
int[]
fixed32
(1)int
Integer
int[]
sfixed32
int
Integer
int[]
int64
long
Long
long[]
uint64
(1)long
Long
long[]
sint64
long
Long
long[]
fixed64
(1)long
Long
long[]
sfixed64
long
Long
long[]
float
float
Float
float[]
double
double
Double
double[]
bool
boolean
Boolean
boolean[]
string
String
String
String[]
bytes
byte[]
byte[]
byte[][]
bytes
(2)ByteString
ByteString
ByteString[]
enum
EnumValueDescriptor
EnumValueDescriptor
EnumValueDescriptor[]
Integer.toUnsignedLong(int)
orLong.toUnsignedString(long)
/BigInteger(String)
to adapt as appropriate.^2 The default behavior for
bytes
isbyte[]
. To parse asByteString
instead, configureFieldOptions.bytes()
for the field.For
message
(andgroup
if proto2) fields, theProtobufDescriptorParserOptions.parsers()
are used for well-known message types (for example,Timestamp
toInstant
), otherwise parsing continues recursively with the thefield's message descriptor
. To skip parsing as a well-known type, configureFieldOptions.wellKnown()
for the field. If the field is repeated, the function return type will be the array-type with component type equal to what the non-repeated field function return type would be (for example,repeated com.google.protobuf.Timestamp
will result injava.time.Instant[]
).Protobuf maps are a special case, which result in a function type that returns a
Map<Object, Object>
, where the keys are the equivalentKeyType
and the values are the equivalentValueType
. To parse as arepeated MapFieldEntry
instead of amap
, configureFieldOptions.map()
for the field.The
FieldPath
context is kept during traversal and is an important part of the returned message functions. Callers will typically use the returned field path to assign appropriate names to the functions.- Parameters:
descriptor
- the descriptoroptions
- the options- Returns:
- the parsed protobuf functions
- See Also:
-