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.
()
| 199 | // NOTE: There are many different base32 implementations so becareful when |
| 200 | // doing any interoperation. |
| 201 | func (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 |
no outgoing calls