1818import com .google .common .base .Splitter ;
1919import com .google .common .net .InetAddresses ;
2020import com .google .common .primitives .Bytes ;
21+ import com .google .protobuf .Descriptors ;
22+ import com .google .protobuf .Message ;
2123import inet .ipaddr .IPAddress ;
2224import inet .ipaddr .IPAddressString ;
2325import jakarta .mail .internet .AddressException ;
3537import org .projectnessie .cel .common .types .ListT ;
3638import org .projectnessie .cel .common .types .StringT ;
3739import org .projectnessie .cel .common .types .Types ;
40+ import org .projectnessie .cel .common .types .pb .DefaultTypeAdapter ;
3841import org .projectnessie .cel .common .types .ref .TypeEnum ;
3942import org .projectnessie .cel .common .types .ref .Val ;
4043import org .projectnessie .cel .common .types .traits .Lister ;
4346/** Defines custom function overloads (the implementation). */
4447final class CustomOverload {
4548
49+ private static final String OVERLOAD_GET_FIELD = "getField" ;
4650 private static final String OVERLOAD_FORMAT = "format" ;
4751 private static final String OVERLOAD_UNIQUE = "unique" ;
4852 private static final String OVERLOAD_STARTS_WITH = "startsWith" ;
@@ -65,6 +69,7 @@ final class CustomOverload {
6569 */
6670 static Overload [] create () {
6771 return new Overload [] {
72+ getField (),
6873 format (),
6974 unique (),
7075 startsWith (),
@@ -82,6 +87,30 @@ static Overload[] create() {
8287 };
8388 }
8489
90+ /**
91+ * Creates a custom function overload for the "getField" operation.
92+ *
93+ * @return The {@link Overload} instance for the "getField" operation.
94+ */
95+ private static Overload getField () {
96+ return Overload .binary (
97+ OVERLOAD_GET_FIELD ,
98+ (msgarg , namearg ) -> {
99+ if (msgarg .type ().typeEnum () != TypeEnum .Object
100+ || namearg .type ().typeEnum () != TypeEnum .String ) {
101+ return Err .newErr ("no such overload" );
102+ }
103+ Message message = msgarg .convertToNative (Message .class );
104+ String fieldName = namearg .convertToNative (String .class );
105+ Descriptors .FieldDescriptor field =
106+ message .getDescriptorForType ().findFieldByName (fieldName );
107+ if (field == null ) {
108+ return Err .newErr ("no such field: " + fieldName );
109+ }
110+ return DefaultTypeAdapter .Instance .nativeToValue (message .getField (field ));
111+ });
112+ }
113+
85114 /**
86115 * Creates a custom binary function overload for the "format" operation.
87116 *
0 commit comments