MarshalJSON returns the JSON encoding of NodeIDs, e.g., a comma separated list.
()
| 165 | // MarshalJSON returns the JSON encoding of NodeIDs, e.g., a comma |
| 166 | // separated list. |
| 167 | func (n NodeIDs) MarshalJSON() ([]byte, error) { |
| 168 | var b bytes.Buffer |
| 169 | l := len(n) - 1 |
| 170 | b.WriteRune('"') |
| 171 | for i, id := range n { |
| 172 | b.WriteString(strconv.Itoa(id)) |
| 173 | if i < l { |
| 174 | b.WriteRune(',') |
| 175 | } |
| 176 | } |
| 177 | b.WriteRune('"') |
| 178 | return b.Bytes(), nil |
| 179 | } |
| 180 | |
| 181 | // UnmarshalJSON parses the JSON-encoded data. |
| 182 | func (n *NodeIDs) UnmarshalJSON(data []byte) error { |
no outgoing calls