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

Function decode

packages/rpc/src/RpcSerialization.ts:474–503  ·  view source on GitHub ↗
(bytes)

Source from the content-addressed store, hash-verified

472 let incomplete: Uint8Array | undefined = undefined
473 return {
474 decode(bytes) {
475 let buf = typeof bytes === "string" ? encoder.encode(bytes) : bytes
476 if (incomplete !== undefined) {
477 const prev = buf
478 bytes = new Uint8Array(incomplete.length + buf.length)
479 bytes.set(incomplete)
480 bytes.set(prev, incomplete.length)
481 buf = bytes
482 incomplete = undefined
483 }
484 try {
485 return unpackr.unpackMultiple(buf)
486 } catch (error_) {
487 const error = error_ as any
488 if (error.incomplete) {
489 const nextIncomplete = buf.subarray(error.lastPosition)
490 const bufferSize = nextIncomplete.length
491 if (isBufferSizeExceeded(bufferSize, maxBufferSize)) {
492 throw new RpcSerializationError({
493 reason: "BufferSizeExceeded",
494 maxBufferSize,
495 bufferSize
496 })
497 }
498 incomplete = nextIncomplete
499 return error.values ?? []
500 }
501 throw error_
502 }
503 },
504 encode: (response) => packr.pack(response)
505 }
506 }

Callers 2

Rpc.test.tsFile · 0.50

Calls 3

isBufferSizeExceededFunction · 0.85
encodeMethod · 0.80
setMethod · 0.65

Tested by 1