MCPcopy Create free account
hub / github.com/cel-expr/cel-go / fieldToVariable

Function fieldToVariable

cel/options.go:847–877  ·  view source on GitHub ↗
(field protoreflect.FieldDescriptor, jsonFieldNames bool)

Source from the content-addressed store, hash-verified

845}
846
847func fieldToVariable(field protoreflect.FieldDescriptor, jsonFieldNames bool) (*decls.VariableDecl, error) {
848 name := string(field.Name())
849 if jsonFieldNames {
850 name = field.JSONName()
851 }
852 if field.IsMap() {
853 mapKey := field.MapKey()
854 mapValue := field.MapValue()
855 keyType, err := fieldToCELType(mapKey)
856 if err != nil {
857 return nil, err
858 }
859 valueType, err := fieldToCELType(mapValue)
860 if err != nil {
861 return nil, err
862 }
863 return decls.NewVariable(name, MapType(keyType, valueType)), nil
864 }
865 if field.IsList() {
866 elemType, err := fieldToCELType(field)
867 if err != nil {
868 return nil, err
869 }
870 return decls.NewVariable(name, ListType(elemType)), nil
871 }
872 celType, err := fieldToCELType(field)
873 if err != nil {
874 return nil, err
875 }
876 return decls.NewVariable(name, celType), nil
877}
878
879// DeclareContextProto returns an option to extend CEL environment with declarations from the given context proto.
880// Each field of the proto defines a variable of the same name in the environment.

Callers 2

ToConfigMethod · 0.85
DeclareContextProtoFunction · 0.85

Calls 6

NewVariableFunction · 0.92
fieldToCELTypeFunction · 0.85
JSONNameMethod · 0.80
NameMethod · 0.65
IsMapMethod · 0.45
IsListMethod · 0.45

Tested by

no test coverage detected