UNPKG

514 BPlain TextView Raw
1import type { encode as S, decode as D } from '@msgpack/msgpack'
2import type { Serialization } from 'async-call-rpc'
3export const Msgpack_Serialization = ({ encode, decode }: { encode: typeof S; decode: typeof D }): Serialization => ({
4 async deserialization(data: any) {
5 if (data instanceof Blob) data = await data.arrayBuffer()
6 if (data instanceof ArrayBuffer) data = new Uint8Array(data)
7 return decode(data)
8 },
9 serialization(data: any) {
10 return encode(data)
11 },
12})