MarshalJSON implements json.Marshaler
()
| 350 | |
| 351 | // MarshalJSON implements json.Marshaler |
| 352 | func (n *Number) MarshalJSON() ([]byte, error) { |
| 353 | t := n.Type() |
| 354 | if t == InvalidType { |
| 355 | return []byte{'0'}, nil |
| 356 | } |
| 357 | out := make([]byte, 0, 32) |
| 358 | switch t { |
| 359 | case Float32Type, Float64Type: |
| 360 | f, _ := n.Float() |
| 361 | return strconv.AppendFloat(out, f, 'f', -1, 64), nil |
| 362 | case IntType: |
| 363 | i, _ := n.Int() |
| 364 | return strconv.AppendInt(out, i, 10), nil |
| 365 | case UintType: |
| 366 | u, _ := n.Uint() |
| 367 | return strconv.AppendUint(out, u, 10), nil |
| 368 | default: |
| 369 | panic("(*Number).typ is invalid") |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | // String implements fmt.Stringer |
| 374 | func (n *Number) String() string { |
no test coverage detected