MCPcopy
hub / github.com/bwmarrin/snowflake / Base32

Method Base32

snowflake.go:201–219  ·  view source on GitHub ↗

Base32 uses the z-base-32 character set but encodes and decodes similar to base58, allowing it to create an even smaller result string. NOTE: There are many different base32 implementations so becareful when doing any interoperation.

()

Source from the content-addressed store, hash-verified

199// NOTE: There are many different base32 implementations so becareful when
200// doing any interoperation.
201func (f ID) Base32() string {
202
203 if f < 32 {
204 return string(encodeBase32Map[f])
205 }
206
207 b := make([]byte, 0, 12)
208 for f >= 32 {
209 b = append(b, encodeBase32Map[f%32])
210 f /= 32
211 }
212 b = append(b, encodeBase32Map[f])
213
214 for x, y := 0, len(b)-1; x < y; x, y = x+1, y-1 {
215 b[x], b[y] = b[y], b[x]
216 }
217
218 return string(b)
219}
220
221// ParseBase32 parses a base32 []byte into a snowflake ID
222// NOTE: There are many different base32 implementations so becareful when

Callers 4

TestPrintAllFunction · 0.80
TestBase32Function · 0.80
BenchmarkParseBase32Function · 0.80
BenchmarkBase32Function · 0.80

Calls

no outgoing calls

Tested by 4

TestPrintAllFunction · 0.64
TestBase32Function · 0.64
BenchmarkParseBase32Function · 0.64
BenchmarkBase32Function · 0.64