Class ProtobufResultWriter

java.lang.Object
io.confluent.kafka.schemaregistry.rules.cel.protobuf.ProtobufResultWriter

public final class ProtobufResultWriter extends Object
Re-shapes a CEL result so that Jackson renders it as protobuf JSON, the counterpart of AvroResultWriter on the Avro path.

A message-level CEL rule returns a map of field name to value, which CelExecutor serializes with Jackson and hands to ProtobufSchema.fromJson. Two CEL values have no protobuf JSON rendering of their own: a decimal is a confluent.type.Decimal message, not a number, and a Variant is a confluent.type.Variant message rather than a POJO Jackson can reflect over. Left alone the first fails with "Expect message object but got: 13.34" and the second throws out of Variant.valueBuffer.

A google.protobuf.Timestamp needs the same treatment for the opposite reason: a CEL timestamp is an Instant, and Jackson renders java.time either not at all or as a numeric epoch, where protobuf JSON wants an RFC 3339 string.

The walk is driven by the target descriptor rather than by the value's Java type, so a decimal produced for a plain numeric field still renders as a number — only a field actually declared as one of these message types is re-shaped. Bytes are emitted as byte[], which Jackson base64-encodes, and base64 is protobuf JSON's encoding for bytes.

  • Field Details

  • Method Details

    • convert

      public static Object convert(Object result, com.google.protobuf.Descriptors.Descriptor descriptor)
      Converts result against descriptor. Anything the descriptor does not describe is returned untouched, so this is safe to call on any CEL result.