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

Method CompileOptions

ext/encoders.go:97–128  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

95}
96
97func (lib *encoderLib) CompileOptions() []cel.EnvOption {
98 opts := []cel.EnvOption{
99 cel.Function("base64.decode",
100 cel.Overload("base64_decode_string", []*cel.Type{cel.StringType}, cel.BytesType,
101 cel.UnaryBinding(func(str ref.Val) ref.Val {
102 s := str.(types.String)
103 return bytesOrError(base64DecodeString(string(s)))
104 }))),
105 cel.Function("base64.encode",
106 cel.Overload("base64_encode_bytes", []*cel.Type{cel.BytesType}, cel.StringType,
107 cel.UnaryBinding(func(bytes ref.Val) ref.Val {
108 b := bytes.(types.Bytes)
109 return stringOrError(base64EncodeBytes([]byte(b)))
110 }))),
111 }
112 if lib.version >= 1 {
113 estimators := []checker.CostOption{
114 checker.OverloadCostEstimate("base64_decode_string", estimateDecode),
115 checker.OverloadCostEstimate("base64_encode_bytes", estimateEncode),
116 checker.OverloadCostEstimate("json_encode_dyn", estimateJSONEncode),
117 }
118 opts = append(opts, cel.CostEstimatorOptions(estimators...))
119 opts = append(opts,
120 cel.Function("json.encode",
121 cel.Overload("json_encode_dyn", []*cel.Type{cel.DynType}, cel.StringType,
122 cel.UnaryBinding(func(val ref.Val) ref.Val {
123 return stringOrError(jsonEncodeValue(val))
124 }))),
125 )
126 }
127 return opts
128}
129
130func (lib *encoderLib) ProgramOptions() []cel.ProgramOption {
131 var opts []cel.ProgramOption

Callers

nothing calls this directly

Calls 10

FunctionFunction · 0.92
OverloadFunction · 0.92
UnaryBindingFunction · 0.92
OverloadCostEstimateFunction · 0.92
CostEstimatorOptionsFunction · 0.92
bytesOrErrorFunction · 0.85
base64DecodeStringFunction · 0.85
stringOrErrorFunction · 0.85
base64EncodeBytesFunction · 0.85
jsonEncodeValueFunction · 0.85

Tested by

no test coverage detected