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

Function pushEach

packages/sql/pg/src/PgProtocol.ts:149–197  ·  view source on GitHub ↗
(chunk, onMessage)

Source from the content-addressed store, hash-verified

147 return messages
148 },
149 pushEach(chunk, onMessage) {
150 if (failed) {
151 throw new ParseError({ message: "Parser cannot be reused after a failure" })
152 }
153 try {
154 append(chunk)
155 while (end - start >= 5) {
156 const length = (buffer[start + 1] << 24) | (buffer[start + 2] << 16) | (buffer[start + 3] << 8) |
157 buffer[start + 4]
158 if (length < 4) {
159 throw new ParseError({ message: `Invalid message length: ${length}` })
160 }
161 if (length > maxMessageSize) {
162 throw new ParseError({
163 message: `Message length ${length} exceeds maxMessageSize ${maxMessageSize}`
164 })
165 }
166 if (end - start < length + 1) break
167 const type = buffer[start]
168 const body = start + 5
169 const limit = start + 1 + length
170 start = limit
171 if (type === BackendType.DataRow) {
172 // `buffer` always starts at byte 0 of `store`, so offsets index both.
173 let row: DataRow<A>
174 try {
175 row = decodeDataRow<A>(buffer, store, 0, body, limit, parser.readField)
176 } catch (error) {
177 // `start` is already past the row, so the stream stays framed.
178 const onFieldError = parser.onFieldError
179 if (onFieldError === undefined || error instanceof ParseError) throw error
180 onFieldError(error)
181 continue
182 }
183 onMessage(row)
184 } else {
185 reader.reset(buffer, body, limit)
186 const message = decodeBackend(type, reader)
187 if (reader.offset !== limit) {
188 throw new ParseError({ message: `Message has ${limit - reader.offset} trailing byte(s)` })
189 }
190 onMessage(message as BackendMessage<A>)
191 }
192 }
193 } catch (error) {
194 failed = true
195 throw error
196 }
197 }
198 }
199 return parser
200}

Callers

nothing calls this directly

Calls 5

decodeDataRowFunction · 0.85
decodeBackendFunction · 0.85
appendFunction · 0.70
onMessageFunction · 0.70
resetMethod · 0.65

Tested by

no test coverage detected