( input: number, output: Uint8Array, offset: number, )
| 124 | } |
| 125 | |
| 126 | function encodeNumber( |
| 127 | input: number, |
| 128 | output: Uint8Array, |
| 129 | offset: number, |
| 130 | ): number { |
| 131 | if (input % 1 === 0) { |
| 132 | const isNegative = input < 0; |
| 133 | if (isNegative && input <= -(2 ** 64)) { |
| 134 | throw new RangeError( |
| 135 | `Cannot encode number: It (${input}) exceeds -(2 ** 64) - 1`, |
| 136 | ); |
| 137 | } else if (input >= 2 ** 64) { |
| 138 | throw new RangeError( |
| 139 | `Cannot encode number: It (${input}) exceeds 2 ** 64 - 1`, |
| 140 | ); |
| 141 | } |
| 142 | return encodeHeader( |
| 143 | isNegative ? 0b001_00000 : 0b000_00000, |
| 144 | isNegative ? -input - 1 : input, |
| 145 | output, |
| 146 | offset, |
| 147 | ); |
| 148 | } |
| 149 | const view = new DataView(output.buffer); |
| 150 | output[offset++] = 0b111_11011; |
| 151 | view.setFloat64(offset, input); |
| 152 | return offset + 8; |
| 153 | } |
| 154 | |
| 155 | function encodeBigInt( |
| 156 | input: bigint, |
no test coverage detected