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

Function makeDataRow

packages/sql/pg/benchmark/PgCodec.ts:50–65  ·  view source on GitHub ↗
(fields: ReadonlyArray<string | Uint8Array>)

Source from the content-addressed store, hash-verified

48assert.deepStrictEqual(normalize(decodeEffect()), normalize(decodePostgresJs()))
49
50const makeDataRow = (fields: ReadonlyArray<string | Uint8Array>): Uint8Array => {
51 const encoded = fields.map((field) => typeof field === "string" ? Buffer.from(field, "utf8") : Buffer.from(field))
52 const length = 4 + 2 + encoded.reduce((total, field) => total + 4 + field.length, 0)
53 const frame = Buffer.allocUnsafe(1 + length)
54 frame[0] = 0x44
55 frame.writeInt32BE(length, 1)
56 frame.writeInt16BE(encoded.length, 5)
57 let offset = 7
58 for (const field of encoded) {
59 frame.writeInt32BE(field.length, offset)
60 offset += 4
61 field.copy(frame, offset)
62 offset += field.length
63 }
64 return frame
65}
66
67const rowsPerParserRun = 100
68const dataRow = makeDataRow(payload.map(({ text }) => text))

Callers 1

PgCodec.tsFile · 0.85

Calls 2

fromMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected