2121import com .google .errorprone .annotations .Immutable ;
2222import com .google .protobuf .ByteString ;
2323import com .google .protobuf .Duration ;
24- import com .google .protobuf .NullValue ;
2524import com .google .protobuf .Timestamp ;
2625import dev .cel .common .annotations .Internal ;
26+ import dev .cel .common .values .CelByteString ;
27+ import dev .cel .common .values .NullValue ;
2728
2829/**
2930 * Represents a primitive literal.
@@ -42,7 +43,7 @@ public abstract class CelConstant {
4243 UnsignedLong .class ,
4344 Double .class ,
4445 String .class ,
45- ByteString .class );
46+ CelByteString .class );
4647
4748 /** Represents the type of the Constant */
4849 public enum Kind {
@@ -92,7 +93,7 @@ public abstract static class CelConstantNotSet {}
9293
9394 public abstract String stringValue ();
9495
95- public abstract ByteString bytesValue ();
96+ public abstract CelByteString bytesValue ();
9697
9798 /**
9899 * @deprecated Do not use. Timestamp is no longer built-in CEL type.
@@ -134,10 +135,43 @@ public static CelConstant ofValue(String value) {
134135 return AutoOneOf_CelConstant .stringValue (value );
135136 }
136137
137- public static CelConstant ofValue (ByteString value ) {
138+ public static CelConstant ofValue (CelByteString value ) {
138139 return AutoOneOf_CelConstant .bytesValue (value );
139140 }
140141
142+ /**
143+ * @deprecated Use native type equivalent {@link #ofValue(NullValue)} instead.
144+ */
145+ @ Deprecated
146+ public static CelConstant ofValue (com .google .protobuf .NullValue unused ) {
147+ return ofValue (NullValue .NULL_VALUE );
148+ }
149+
150+ /**
151+ * @deprecated Use native type equivalent {@link #ofValue(CelByteString)} instead.
152+ */
153+ @ Deprecated
154+ public static CelConstant ofValue (ByteString value ) {
155+ CelByteString celByteString = CelByteString .of (value .toByteArray ());
156+ return ofValue (celByteString );
157+ }
158+
159+ /**
160+ * @deprecated Do not use. Duration is no longer built-in CEL type.
161+ */
162+ @ Deprecated
163+ public static CelConstant ofValue (Duration value ) {
164+ return AutoOneOf_CelConstant .durationValue (value );
165+ }
166+
167+ /**
168+ * @deprecated Do not use. Timestamp is no longer built-in CEL type.
169+ */
170+ @ Deprecated
171+ public static CelConstant ofValue (Timestamp value ) {
172+ return AutoOneOf_CelConstant .timestampValue (value );
173+ }
174+
141175 /** Checks whether the provided Java object is a valid CelConstant value. */
142176 public static boolean isConstantValue (Object value ) {
143177 return CONSTANT_CLASSES .contains (value .getClass ());
@@ -163,26 +197,10 @@ public static CelConstant ofObjectValue(Object value) {
163197 return ofValue ((double ) value );
164198 } else if (value instanceof String ) {
165199 return ofValue ((String ) value );
166- } else if (value instanceof ByteString ) {
167- return ofValue ((ByteString ) value );
200+ } else if (value instanceof CelByteString ) {
201+ return ofValue ((CelByteString ) value );
168202 }
169203
170204 throw new IllegalArgumentException ("Value is not a CelConstant: " + value );
171205 }
172-
173- /**
174- * @deprecated Do not use. Duration is no longer built-in CEL type.
175- */
176- @ Deprecated
177- public static CelConstant ofValue (Duration value ) {
178- return AutoOneOf_CelConstant .durationValue (value );
179- }
180-
181- /**
182- * @deprecated Do not use. Timestamp is no longer built-in CEL type.
183- */
184- @ Deprecated
185- public static CelConstant ofValue (Timestamp value ) {
186- return AutoOneOf_CelConstant .timestampValue (value );
187- }
188206}
0 commit comments