(value: unknown)
| 874 | * words from there rather than from a returned array, so neither allocates. |
| 875 | */ |
| 876 | const uuidWords = (value: unknown): void => { |
| 877 | const text = requireString(value, "uuid") |
| 878 | if ( |
| 879 | text.length !== 36 || text.charCodeAt(8) !== 45 || text.charCodeAt(13) !== 45 || |
| 880 | text.charCodeAt(18) !== 45 || text.charCodeAt(23) !== 45 |
| 881 | ) { |
| 882 | return fail(`Expected a UUID, received "${text}"`) |
| 883 | } |
| 884 | for (let word = 0; word < 4; word++) { |
| 885 | let bits = 0 |
| 886 | let valid = 0 |
| 887 | for (let i = word * 4; i < word * 4 + 4; i++) { |
| 888 | const at = uuidOffsets[i] |
| 889 | const high = hexAt(text, at) |
| 890 | const low = hexAt(text, at + 1) |
| 891 | valid |= high | low |
| 892 | bits = (bits << 8) | (high << 4) | low |
| 893 | } |
| 894 | if (valid < 0) { |
| 895 | return fail(`Expected a UUID, received "${text}"`) |
| 896 | } |
| 897 | uuidWord[word] = bits |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | const encodeUuid = (value: unknown): Uint8Array => { |
| 902 | uuidWords(value) |
no test coverage detected