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

Function encodeUtf8Prefixed

packages/sql/pg/src/PgTypes.ts:173–195  ·  view source on GitHub ↗
(text: string, prefix: number)

Source from the content-addressed store, hash-verified

171
172/** As `encodeUtf8`, but leaves `prefix` bytes free at the front. */
173const encodeUtf8Prefixed = (text: string, prefix: number): Uint8Array => {
174 const length = text.length
175 if (length <= asciiEncodeLimit) {
176 const bytes = new Uint8Array(prefix + length)
177 let i = 0
178 for (; i < length; i++) {
179 const code = text.charCodeAt(i)
180 if (code > 0x7f) break
181 bytes[prefix + i] = code
182 }
183 if (i === length) return bytes
184 }
185 const written = encodeUtf8Scratch(text)
186 if (written === -1) {
187 const body = textEncoder.encode(text)
188 const bytes = new Uint8Array(prefix + body.length)
189 bytes.set(body, prefix)
190 return bytes
191 }
192 const bytes = new Uint8Array(prefix + written)
193 bytes.set(scratchUtf8.subarray(0, written), prefix)
194 return bytes
195}
196
197/**
198 * A view of `size` bytes at `offset`, or `bytes` itself when that is already

Callers 1

PgTypes.tsFile · 0.85

Calls 3

encodeUtf8ScratchFunction · 0.85
encodeMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected