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

Method Binary

ext/formatting.go:345–364  ·  view source on GitHub ↗

Binary implements formatStringInterpolator.Binary.

(arg ref.Val, locale string)

Source from the content-addressed store, hash-verified

343
344// Binary implements formatStringInterpolator.Binary.
345func (c *stringFormatter) Binary(arg ref.Val, locale string) (string, error) {
346 switch arg.Type() {
347 case types.IntType:
348 argInt := arg.Value().(int64)
349 // locale is intentionally unused as integers formatted as binary
350 // strings are locale-independent
351 return fmt.Sprintf("%b", argInt), nil
352 case types.UintType:
353 argInt := arg.Value().(uint64)
354 return fmt.Sprintf("%b", argInt), nil
355 case types.BoolType:
356 argBool := arg.Value().(bool)
357 if argBool {
358 return "1", nil
359 }
360 return "0", nil
361 default:
362 return "", binaryFormatError(runtimeID, arg.Type().TypeName())
363 }
364}
365
366// Hex implements formatStringInterpolator.Hex.
367func (c *stringFormatter) Hex(useUpper bool) func(ref.Val, string) (string, error) {

Callers

nothing calls this directly

Calls 4

binaryFormatErrorFunction · 0.85
TypeMethod · 0.65
ValueMethod · 0.65
TypeNameMethod · 0.65

Tested by

no test coverage detected