( input: bigint, output: Uint8Array, offset: number, )
| 153 | } |
| 154 | |
| 155 | function encodeBigInt( |
| 156 | input: bigint, |
| 157 | output: Uint8Array, |
| 158 | offset: number, |
| 159 | ): number { |
| 160 | const isNegative = input < 0n; |
| 161 | if (isNegative) input = -input - 1n; |
| 162 | if (input >= 2n ** 64n) { |
| 163 | output[offset++] = isNegative ? 0b110_00011 : 0b110_00010; |
| 164 | const bytes = calcBytes(input); |
| 165 | offset = encodeHeader(0b010_00000, bytes, output, offset); |
| 166 | for (let i = bytes - 1; i >= 0; --i) { |
| 167 | output[offset + i] = Number(input & 0xFFn); |
| 168 | input >>= 8n; |
| 169 | } |
| 170 | return offset + bytes; |
| 171 | } |
| 172 | return encodeHeader( |
| 173 | isNegative ? 0b001_00000 : 0b000_00000, |
| 174 | input, |
| 175 | output, |
| 176 | offset, |
| 177 | ); |
| 178 | } |
| 179 | |
| 180 | function encodeUint8Array( |
| 181 | input: Uint8Array, |
no test coverage detected