| 2587 | } |
| 2588 | } |
| 2589 | encodeExtension(ext) { |
| 2590 | const size = ext.data.length; |
| 2591 | if (size === 1) { |
| 2592 | this.writeU8(0xd4); |
| 2593 | } else if (size === 2) { |
| 2594 | this.writeU8(0xd5); |
| 2595 | } else if (size === 4) { |
| 2596 | this.writeU8(0xd6); |
| 2597 | } else if (size === 8) { |
| 2598 | this.writeU8(0xd7); |
| 2599 | } else if (size === 16) { |
| 2600 | this.writeU8(0xd8); |
| 2601 | } else if (size < 0x100) { |
| 2602 | this.writeU8(0xc7); |
| 2603 | this.writeU8(size); |
| 2604 | } else if (size < 0x10000) { |
| 2605 | this.writeU8(0xc8); |
| 2606 | this.writeU16(size); |
| 2607 | } else if (size < 0x100000000) { |
| 2608 | this.writeU8(0xc9); |
| 2609 | this.writeU32(size); |
| 2610 | } else { |
| 2611 | throw new Error(`Too large extension object: ${size}`); |
| 2612 | } |
| 2613 | this.writeI8(ext.type); |
| 2614 | this.writeU8a(ext.data); |
| 2615 | } |
| 2616 | writeU8(value) { |
| 2617 | this.ensureBufferSizeToWrite(1); |
| 2618 | this.view.setUint8(this.pos, value); |