MarshalJSON implements encoding/json Marshaler interface
()
| 189 | |
| 190 | // MarshalJSON implements encoding/json Marshaler interface |
| 191 | func (id ID) MarshalJSON() ([]byte, error) { |
| 192 | if id.IsNil() { |
| 193 | return []byte("null"), nil |
| 194 | } |
| 195 | text := make([]byte, encodedLen+2) |
| 196 | encode(text[1:encodedLen+1], id[:]) |
| 197 | text[0], text[encodedLen+1] = '"', '"' |
| 198 | return text, nil |
| 199 | } |
| 200 | |
| 201 | // encode by unrolling the stdlib base32 algorithm + removing all safe checks |
| 202 | func encode(dst, id []byte) { |