Class ProtoAdapter


  • @Immutable
    @CheckReturnValue
    @Internal
    public final class ProtoAdapter
    extends java.lang.Object
    The ProtoAdapter utilities handle conversion between native Java objects which represent CEL values and well-known protobuf counterparts.

    How a protobuf is adapted can depend on both the set of Descriptor values as well as on feature-flags. Whereas in the past such conversions were performed as static method calls, this class represents an evolving trend toward conditional conversion.

    CEL Library Internals. Do Not Use.

    • Field Detail

      • INT_CONVERTER

        public static final BidiConverter<java.lang.Number,​java.lang.Number> INT_CONVERTER
        Int converter handles bidirectional conversions between int32 <-> int64 values.

        Note: Unlike the RuntimeHelpers#INT32_TO_INT64 and RuntimeHelpers#INT64_TO_INT32 converter objects, the converter takes a Number as input and produces a Number as output in an effort to make the coverters more tolerant of Java native values which may enter the evaluation via DYN inputs.

      • SIGNED_UINT32_CONVERTER

        public static final BidiConverter<java.lang.Number,​java.lang.Number> SIGNED_UINT32_CONVERTER
        Signed uint converter handles bidirectional conversions between uint32 <-> uint64 values.

        Note: Unlike the RuntimeHelpers#UINT32_TO_UINT64 and RuntimeHelpers#UINT64_TO_UINT32 converter objects, the converter takes a Number as input and produces a Number as output in an effort to make the coverters more tolerant of Java native values which may enter the evaluation via DYN inputs.

        If the long being converted to a uint exceeds 32 bits, an IllegalArgumentException will be thrown.

      • UNSIGNED_UINT32_CONVERTER

        public static final BidiConverter<java.lang.Number,​java.lang.Number> UNSIGNED_UINT32_CONVERTER
        Unigned uint converter handles bidirectional conversions between uint32 <-> uint64 values.

        Note: Unlike the RuntimeHelpers#UINT32_TO_UINT64 and RuntimeHelpers#UINT64_TO_UINT32 converter objects, the converter takes a Number as input and produces a Number as output in an effort to make the coverters more tolerant of Java native values which may enter the evaluation via DYN inputs.

        If the long being converted to a uint exceeds 32 bits, an IllegalArgumentException will be thrown.

      • UNSIGNED_UINT64_CONVERTER

        public static final BidiConverter<java.lang.Number,​java.lang.Number> UNSIGNED_UINT64_CONVERTER
        Unsigned uint64 converter which adapts from a long value on the wire to an UnsignedLong.
      • DOUBLE_CONVERTER

        public static final BidiConverter<java.lang.Number,​java.lang.Number> DOUBLE_CONVERTER
        Double converter handles bidirectional conversions between float32 <-> float64 values.

        Note: Unlike the RuntimeHelpers#FLOAT_TO_DOUBLE and RuntimeHelpers#DOUBLE_TO_FLOAT converter objects, the converter takes a Number as input and produces a Number as output in an effort to make the coverters more tolerant of Java native values which may enter the evaluation via DYN inputs.

    • Constructor Detail

      • ProtoAdapter

        public ProtoAdapter​(DynamicProto dynamicProto,
                            boolean enableUnsignedLongs)
    • Method Detail

      • adaptProtoToValue

        public java.lang.Object adaptProtoToValue​(MessageOrBuilder proto)
        Adapts a protobuf MessageOrBuilder into a Java object understood by CEL.

        In some instances the input message is also the output value.

      • adaptFieldToValue

        public java.util.Optional<java.lang.Object> adaptFieldToValue​(Descriptors.FieldDescriptor fieldDescriptor,
                                                                      java.lang.Object fieldValue)
      • adaptValueToFieldType

        public java.util.Optional<java.lang.Object> adaptValueToFieldType​(Descriptors.FieldDescriptor fieldDescriptor,
                                                                          java.lang.Object fieldValue)
      • adaptValueToProto

        public java.util.Optional<Message> adaptValueToProto​(java.lang.Object value,
                                                             java.lang.String protoTypeName)
        Adapt the Java object value to the given protobuf protoTypeName if possible.

        If the Java value can be represented as a proto Message, then a conversion will be performed. In some cases, the input value will be a Message, but the protoTypeName will indicate an alternative packaging of the value which needs to be considered, such as a packing an google.protobuf.StringValue into a Any value.