MCPcopy Create free account
hub / github.com/middleapi/orpc / decodeRawMessage

Function decodeRawMessage

packages/standard-server-peer/src/codec.ts:396–417  ·  view source on GitHub ↗
(raw: EncodedMessage)

Source from the content-addressed store, hash-verified

394}
395
396async function decodeRawMessage(raw: EncodedMessage): Promise<{ json: any, buffer?: Uint8Array }> {
397 if (typeof raw === 'string') {
398 return { json: JSON.parse(raw) }
399 }
400
401 const buffer = raw instanceof Uint8Array ? raw : new Uint8Array(raw)
402
403 const delimiterIndex = buffer.indexOf(JSON_AND_BINARY_DELIMITER)
404
405 if (delimiterIndex === -1) {
406 const jsonPart = new TextDecoder().decode(buffer)
407 return { json: JSON.parse(jsonPart) }
408 }
409
410 const jsonPart = new TextDecoder().decode(buffer.subarray(0, delimiterIndex))
411 const bufferPart = buffer.subarray(delimiterIndex + 1)
412
413 return {
414 json: JSON.parse(jsonPart),
415 buffer: bufferPart,
416 }
417}

Callers 2

decodeRequestMessageFunction · 0.85
decodeResponseMessageFunction · 0.85

Calls 1

decodeMethod · 0.65

Tested by

no test coverage detected