MCPcopy Create free account
hub / github.com/Effect-TS/effect / uuidWords

Function uuidWords

packages/sql/pg/src/PgTypes.ts:876–899  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

874 * words from there rather than from a returned array, so neither allocates.
875 */
876const 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
901const encodeUuid = (value: unknown): Uint8Array => {
902 uuidWords(value)

Callers 2

encodeUuidFunction · 0.85
writeUuidFunction · 0.85

Calls 3

requireStringFunction · 0.85
hexAtFunction · 0.85
failFunction · 0.70

Tested by

no test coverage detected