MCPcopy
hub / github.com/rs/xid / MarshalJSON

Method MarshalJSON

id.go:191–199  ·  view source on GitHub ↗

MarshalJSON implements encoding/json Marshaler interface

()

Source from the content-addressed store, hash-verified

189
190// MarshalJSON implements encoding/json Marshaler interface
191func (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
202func encode(dst, id []byte) {

Callers

nothing calls this directly

Calls 2

IsNilMethod · 0.95
encodeFunction · 0.85

Tested by

no test coverage detected