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

Method Binary

ext/formatting_v2.go:315–341  ·  view source on GitHub ↗

Binary implements formatStringInterpolatorV2.Binary.

(arg ref.Val)

Source from the content-addressed store, hash-verified

313
314// Binary implements formatStringInterpolatorV2.Binary.
315func (c *stringFormatterV2) Binary(arg ref.Val) (string, error) {
316 switch arg.Type() {
317 case types.BoolType:
318 argBool, ok := arg.Value().(bool)
319 if !ok {
320 return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.BoolType)
321 }
322 if argBool {
323 return "1", nil
324 }
325 return "0", nil
326 case types.IntType:
327 argInt, ok := arg.Value().(int64)
328 if !ok {
329 return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.IntType)
330 }
331 return strconv.FormatInt(argInt, 2), nil
332 case types.UintType:
333 argUint, ok := arg.Value().(uint64)
334 if !ok {
335 return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.UintType)
336 }
337 return strconv.FormatUint(argUint, 2), nil
338 default:
339 return "", binaryFormatErrorV2(runtimeID, arg.Type().TypeName())
340 }
341}
342
343// Hex implements formatStringInterpolatorV2.Hex.
344func (c *stringFormatterV2) Hex(useUpper bool) func(ref.Val) (string, error) {

Callers

nothing calls this directly

Calls 4

binaryFormatErrorV2Function · 0.85
TypeMethod · 0.65
ValueMethod · 0.65
TypeNameMethod · 0.65

Tested by

no test coverage detected