( majorType: number, input: number | bigint, output: Uint8Array, offset: number, )
| 95 | } |
| 96 | |
| 97 | function encodeHeader( |
| 98 | majorType: number, |
| 99 | input: number | bigint, |
| 100 | output: Uint8Array, |
| 101 | offset: number, |
| 102 | ): number { |
| 103 | if (input < 24) output[offset++] = majorType + Number(input); |
| 104 | else if (input < 2 ** 8) { |
| 105 | output[offset++] = majorType + 0b000_11000; |
| 106 | output[offset++] = Number(input); |
| 107 | } else { |
| 108 | const view = new DataView(output.buffer); |
| 109 | if (input < 2 ** 16) { |
| 110 | output[offset++] = majorType + 0b000_11001; |
| 111 | view.setUint16(offset, Number(input)); |
| 112 | offset += 2; |
| 113 | } else if (input < 2 ** 32) { |
| 114 | output[offset++] = majorType + 0b000_11010; |
| 115 | view.setUint32(offset, Number(input)); |
| 116 | offset += 4; |
| 117 | } else { |
| 118 | output[offset++] = majorType + 0b000_11011; |
| 119 | view.setBigUint64(offset, BigInt(input)); |
| 120 | offset += 8; |
| 121 | } |
| 122 | } |
| 123 | return offset; |
| 124 | } |
| 125 | |
| 126 | function encodeNumber( |
| 127 | input: number, |
no outgoing calls
no test coverage detected