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

Function readField

packages/effect/src/unstable/eventlog/EventLogSessionAuth.ts:216–244  ·  view source on GitHub ↗
(
  payload: Uint8Array,
  state: { offset: number }
)

Source from the content-addressed store, hash-verified

214 ) >>> 0
215
216const readField = (
217 payload: Uint8Array,
218 state: { offset: number }
219): Effect.Effect<Uint8Array, EventLogSessionAuthError> => {
220 if (state.offset + constLengthPrefixBytes > payload.byteLength) {
221 return Effect.fail(
222 new EventLogSessionAuthError({
223 reason: "InvalidPayload",
224 message: "Session auth payload is truncated before field length"
225 })
226 )
227 }
228
229 const length = readLength(payload, state.offset)
230 state.offset += constLengthPrefixBytes
231
232 if (state.offset + length > payload.byteLength) {
233 return Effect.fail(
234 new EventLogSessionAuthError({
235 reason: "InvalidPayload",
236 message: "Session auth payload is truncated inside a field"
237 })
238 )
239 }
240
241 const field = payload.slice(state.offset, state.offset + length)
242 state.offset += length
243 return Effect.succeed(field)
244}
245
246const bytesToHex = (bytes: Uint8Array): string => {
247 let hex = ""

Callers 1

Calls 3

readLengthFunction · 0.85
failMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected