| 1 | import { encode, decode } from 'cborg' |
| 2 | import { CustomProgressEvent } from 'progress-events' |
| 3 | import type { ValueCodec } from 'it-rpc' |
| 4 | |
| 5 | export const customProgressEventCodec: ValueCodec<CustomProgressEvent> = { |
| 6 | type: 4099, |
| 7 | canEncode: (val) => val instanceof CustomProgressEvent, |
| 8 | encode: (val, codec, context, invocation) => encode({ |
| 9 | type: val.type, |
| 10 | detail: codec.toValue(val.detail, context, invocation) |
| 11 | }), |
| 12 | decode: (val, codec, pushable, invocation) => { |
| 13 | const { type, detail } = decode(val) |
| 14 | |
| 15 | return new CustomProgressEvent(type, codec.fromValue(detail, pushable, invocation)) |
| 16 | } |
| 17 | } |