| 2427 | } |
| 2428 | } |
| 2429 | encodeNumber(object) { |
| 2430 | if (Number.isSafeInteger(object)) { |
| 2431 | if (object >= 0) { |
| 2432 | if (object < 0x80) { |
| 2433 | this.writeU8(object); |
| 2434 | } else if (object < 0x100) { |
| 2435 | this.writeU8(0xcc); |
| 2436 | this.writeU8(object); |
| 2437 | } else if (object < 0x10000) { |
| 2438 | this.writeU8(0xcd); |
| 2439 | this.writeU16(object); |
| 2440 | } else if (object < 0x100000000) { |
| 2441 | this.writeU8(0xce); |
| 2442 | this.writeU32(object); |
| 2443 | } else { |
| 2444 | this.writeU8(0xcf); |
| 2445 | this.writeU64(object); |
| 2446 | } |
| 2447 | } else { |
| 2448 | if (object >= -0x20) { |
| 2449 | this.writeU8(0xe0 | object + 0x20); |
| 2450 | } else if (object >= -0x80) { |
| 2451 | this.writeU8(0xd0); |
| 2452 | this.writeI8(object); |
| 2453 | } else if (object >= -0x8000) { |
| 2454 | this.writeU8(0xd1); |
| 2455 | this.writeI16(object); |
| 2456 | } else if (object >= -0x80000000) { |
| 2457 | this.writeU8(0xd2); |
| 2458 | this.writeI32(object); |
| 2459 | } else { |
| 2460 | this.writeU8(0xd3); |
| 2461 | this.writeI64(object); |
| 2462 | } |
| 2463 | } |
| 2464 | } else { |
| 2465 | if (this.forceFloat32) { |
| 2466 | this.writeU8(0xca); |
| 2467 | this.writeF32(object); |
| 2468 | } else { |
| 2469 | this.writeU8(0xcb); |
| 2470 | this.writeF64(object); |
| 2471 | } |
| 2472 | } |
| 2473 | } |
| 2474 | writeStringHeader(byteLength) { |
| 2475 | if (byteLength < 32) { |
| 2476 | this.writeU8(0xa0 + byteLength); |