Binary implements formatStringInterpolatorV2.Binary.
(arg ref.Val)
| 313 | |
| 314 | // Binary implements formatStringInterpolatorV2.Binary. |
| 315 | func (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. |
| 344 | func (c *stringFormatterV2) Hex(useUpper bool) func(ref.Val) (string, error) { |
nothing calls this directly
no test coverage detected