MCPcopy
hub / github.com/tinylib/msgp / MarshalJSON

Method MarshalJSON

msgp/number.go:352–371  ·  view source on GitHub ↗

MarshalJSON implements json.Marshaler

()

Source from the content-addressed store, hash-verified

350
351// MarshalJSON implements json.Marshaler
352func (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
374func (n *Number) String() string {

Callers 3

rwTimeBytesFunction · 0.45
rwExtensionBytesFunction · 0.45
rwTimeFunction · 0.45

Calls 4

TypeMethod · 0.95
FloatMethod · 0.95
IntMethod · 0.95
UintMethod · 0.95

Tested by

no test coverage detected