Class ProtobufDescriptorParser
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ProtobufFunctionsparse(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) Createsmessagefunctionsthan can parse messages according to the givendescriptorandoptions. The resulting message functions require that the passed-inmessages' descriptorbe the same instance asdescriptor.Parsing proceeds through each
descriptor fieldthat matchesFieldOptions.include()}. By default, this istruefor all fields.For simple types, the fields are parsed as:
^1 Unsigned 32-bit and 64-bit integers are represented using their signed counterpart, with the top bit being stored in the sign bit. This matches the Java protobuf behavior, scalar. Users may useprotobuf typefunction type (no presence) function type (presence) function type (repeated) int32intIntegerint[]uint32(1)intIntegerint[]sint32intIntegerint[]fixed32(1)intIntegerint[]sfixed32intIntegerint[]int64longLonglong[]uint64(1)longLonglong[]sint64longLonglong[]fixed64(1)longLonglong[]sfixed64longLonglong[]floatfloatFloatfloat[]doubledoubleDoubledouble[]boolbooleanBooleanboolean[]stringStringStringString[]bytesbyte[]byte[]byte[][]bytes(2)ByteStringByteStringByteString[]enumEnumValueDescriptorEnumValueDescriptorEnumValueDescriptor[]Integer.toUnsignedLong(int)orLong.toUnsignedString(long)/BigInteger(String)to adapt as appropriate.^2 The default behavior for
bytesisbyte[]. To parse asByteStringinstead, configureFieldOptions.bytes()for the field.For
message(andgroupif proto2) fields, theProtobufDescriptorParserOptions.parsers()are used for well-known message types (for example,TimestamptoInstant), 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.Timestampwill 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 equivalentKeyTypeand the values are the equivalentValueType. To parse as arepeated MapFieldEntryinstead of amap, configureFieldOptions.map()for the field.The
FieldPathcontext 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:
-