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

Function encode

id.go:202–226  ·  view source on GitHub ↗

encode by unrolling the stdlib base32 algorithm + removing all safe checks

(dst, id []byte)

Source from the content-addressed store, hash-verified

200
201// encode by unrolling the stdlib base32 algorithm + removing all safe checks
202func encode(dst, id []byte) {
203 _ = dst[19]
204 _ = id[11]
205
206 dst[19] = encoding[(id[11]<<4)&0x1F]
207 dst[18] = encoding[(id[11]>>1)&0x1F]
208 dst[17] = encoding[(id[11]>>6)|(id[10]<<2)&0x1F]
209 dst[16] = encoding[id[10]>>3]
210 dst[15] = encoding[id[9]&0x1F]
211 dst[14] = encoding[(id[9]>>5)|(id[8]<<3)&0x1F]
212 dst[13] = encoding[(id[8]>>2)&0x1F]
213 dst[12] = encoding[id[8]>>7|(id[7]<<1)&0x1F]
214 dst[11] = encoding[(id[7]>>4)|(id[6]<<4)&0x1F]
215 dst[10] = encoding[(id[6]>>1)&0x1F]
216 dst[9] = encoding[(id[6]>>6)|(id[5]<<2)&0x1F]
217 dst[8] = encoding[id[5]>>3]
218 dst[7] = encoding[id[4]&0x1F]
219 dst[6] = encoding[id[4]>>5|(id[3]<<3)&0x1F]
220 dst[5] = encoding[(id[3]>>2)&0x1F]
221 dst[4] = encoding[id[3]>>7|(id[2]<<1)&0x1F]
222 dst[3] = encoding[(id[2]>>4)|(id[1]<<4)&0x1F]
223 dst[2] = encoding[(id[1]>>1)&0x1F]
224 dst[1] = encoding[(id[1]>>6)|(id[0]<<2)&0x1F]
225 dst[0] = encoding[id[0]>>3]
226}
227
228// UnmarshalText implements encoding/text TextUnmarshaler interface
229func (id *ID) UnmarshalText(text []byte) error {

Callers 4

StringMethod · 0.85
EncodeMethod · 0.85
MarshalTextMethod · 0.85
MarshalJSONMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…