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

Function encodeRawMessage

packages/standard-server-peer/src/codec.ts:382–394  ·  view source on GitHub ↗
(data: object, blob?: Blob)

Source from the content-addressed store, hash-verified

380const JSON_AND_BINARY_DELIMITER = 0xFF
381
382async function encodeRawMessage(data: object, blob?: Blob): Promise<EncodedMessage> {
383 const json = stringifyJSON(data)
384
385 if (blob === undefined || blob.size === 0) {
386 return json
387 }
388
389 return readAsBuffer(new Blob([
390 new TextEncoder().encode(json),
391 new Uint8Array([JSON_AND_BINARY_DELIMITER]),
392 blob,
393 ]))
394}
395
396async function decodeRawMessage(raw: EncodedMessage): Promise<{ json: any, buffer?: Uint8Array }> {
397 if (typeof raw === 'string') {

Callers 2

encodeRequestMessageFunction · 0.85
encodeResponseMessageFunction · 0.85

Calls 3

stringifyJSONFunction · 0.90
readAsBufferFunction · 0.90
encodeMethod · 0.65

Tested by

no test coverage detected