tidToNum converts a Bluesky TID into a 64-bit number.
(tid string)
| 34 | |
| 35 | // tidToNum converts a Bluesky TID into a 64-bit number. |
| 36 | func TidToNum(tid string) (uint64, error) { |
| 37 | if len(tid) != 13 { |
| 38 | return 0, fmt.Errorf("TID must be 13 characters") |
| 39 | } |
| 40 | |
| 41 | var num uint64 |
| 42 | for _, c := range tid { |
| 43 | index := strings.IndexRune(tidChars, c) |
| 44 | if index == -1 { |
| 45 | return 0, fmt.Errorf("invalid character in TID: %c", c) |
| 46 | } |
| 47 | num = (num << 5) | uint64(index) |
| 48 | } |
| 49 | |
| 50 | // Verify the first bit is 0 |
| 51 | if (num & 0x8000000000000000) != 0 { |
| 52 | return 0, fmt.Errorf("first bit must be 0") |
| 53 | } |
| 54 | |
| 55 | return num, nil |
| 56 | } |
no outgoing calls
no test coverage detected