( input: CborType, output: Uint8Array, offset: number, )
| 61 | } |
| 62 | |
| 63 | export function encode( |
| 64 | input: CborType, |
| 65 | output: Uint8Array, |
| 66 | offset: number, |
| 67 | ): number { |
| 68 | switch (typeof input) { |
| 69 | case "undefined": |
| 70 | output[offset++] = 0b111_10111; |
| 71 | break; |
| 72 | case "boolean": |
| 73 | output[offset++] = input ? 0b111_10101 : 0b111_10100; |
| 74 | break; |
| 75 | case "number": |
| 76 | return encodeNumber(input, output, offset); |
| 77 | case "bigint": |
| 78 | return encodeBigInt(input, output, offset); |
| 79 | case "string": |
| 80 | return encodeString(input, output, offset); |
| 81 | default: |
| 82 | if (input === null) output[offset++] = 0b111_10110; |
| 83 | else if (input instanceof Uint8Array) { |
| 84 | return encodeUint8Array(input, output, offset); |
| 85 | } else if (input instanceof Date) { |
| 86 | return encodeDate(input, output, offset); |
| 87 | } else if (input instanceof CborTag) { |
| 88 | return encodeTag(input, output, offset); |
| 89 | } else if (input instanceof Map) return encodeMap(input, output, offset); |
| 90 | else if (input instanceof Array) { |
| 91 | return encodeArray(input, output, offset); |
| 92 | } else return encodeObject(input, output, offset); |
| 93 | } |
| 94 | return offset; |
| 95 | } |
| 96 | |
| 97 | function encodeHeader( |
| 98 | majorType: number, |
no test coverage detected