MarshalJSON encodes the wrapped statistics into JSON.
()
| 25 | |
| 26 | // MarshalJSON encodes the wrapped statistics into JSON. |
| 27 | func (m *Statistics) MarshalJSON() ([]byte, error) { |
| 28 | var w bytes.Buffer |
| 29 | w.Grow(256) |
| 30 | w.WriteString(`{"packet_received":`) |
| 31 | w.WriteString(strconv.FormatUint(m.PacketReceived.Load(), 10)) |
| 32 | w.WriteString(`,"packet_sent":`) |
| 33 | w.WriteString(strconv.FormatUint(m.PacketSent.Load(), 10)) |
| 34 | w.WriteString(`,"packet_lost":`) |
| 35 | w.WriteString(strconv.FormatUint(m.PacketLost.Load(), 10)) |
| 36 | w.WriteString(`,"message_received":`) |
| 37 | w.WriteString(strconv.FormatUint(m.MessageReceived.Load(), 10)) |
| 38 | w.WriteString(`,"message_sent":`) |
| 39 | w.WriteString(strconv.FormatUint(m.MessageSent.Load(), 10)) |
| 40 | w.WriteString(`,"disconnect_times":`) |
| 41 | w.WriteString(strconv.FormatUint(uint64(m.DisconnectTimes.Load()), 10)) |
| 42 | w.WriteString(`,"lost_times":`) |
| 43 | w.WriteString(strconv.FormatUint(uint64(m.LostTimes.Load()), 10)) |
| 44 | w.WriteString(`,"last_message_time":`) |
| 45 | w.WriteString(strconv.FormatInt(m.LastMessageTime.Load(), 10)) |
| 46 | w.WriteByte('}') |
| 47 | return w.Bytes(), nil |
| 48 | } |