Class ProtobufDescriptorParser

java.lang.Object
io.deephaven.protobuf.ProtobufDescriptorParser

public final class ProtobufDescriptorParser extends Object
  • Constructor Details

    • ProtobufDescriptorParser

      public ProtobufDescriptorParser()
  • Method Details

    • parse

      public static ProtobufFunctions parse(com.google.protobuf.Descriptors.Descriptor descriptor, ProtobufDescriptorParserOptions options)
      Creates message functions than can parse messages according to the given descriptor and options. The resulting message functions require that the passed-in messages' descriptor be the same instance as descriptor.

      Parsing proceeds through each descriptor field that matches FieldOptions.include()}. By default, this is true 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[]
      ^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 use Integer.toUnsignedLong(int) or Long.toUnsignedString(long) / BigInteger(String) to adapt as appropriate.

      ^2 The default behavior for bytes is byte[]. To parse as ByteString instead, configure FieldOptions.bytes() for the field.

      For message (and group if proto2) fields, the ProtobufDescriptorParserOptions.parsers() are used for well-known message types (for example, Timestamp to Instant), otherwise parsing continues recursively with the the field's message descriptor. To skip parsing as a well-known type, configure FieldOptions.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 in java.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 equivalent KeyType and the values are the equivalent ValueType. To parse as a repeated MapFieldEntry instead of a map, configure FieldOptions.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 descriptor
      options - the options
      Returns:
      the parsed protobuf functions
      See Also: