()
| 710 | } |
| 711 | |
| 712 | parse(): Uint8Array { |
| 713 | // Don't parse again if not needed |
| 714 | if (this.parsed) return this.sections[0]; |
| 715 | |
| 716 | this.index = 4; |
| 717 | |
| 718 | while (this.index < this.data.length) { |
| 719 | const payloadType = this.data[this.index++]; |
| 720 | if (payloadType === 0) { |
| 721 | // BSON spec specifies that this is a 32-bit signed integer: https://bsonspec.org/spec.html#:~:text=%3A%3A%3D-,int32,-e_list%20unsigned_byte(0 |
| 722 | // While allowing negative sizes seems odd, in practice we never expect a negative size. Also, the server's 16mb limit for BSON documents leaves plenty |
| 723 | // of room in an int32 to store a document of the max BSON size that the server supports |
| 724 | const bsonSize = readInt32LE(this.data, this.index); |
| 725 | const bin = this.data.subarray(this.index, this.index + bsonSize); |
| 726 | |
| 727 | this.sections.push(bin); |
| 728 | |
| 729 | this.index += bsonSize; |
| 730 | } else if (payloadType === 1) { |
| 731 | // It was decided that no driver makes use of payload type 1 |
| 732 | |
| 733 | // TODO(NODE-3483): Replace with MongoDeprecationError |
| 734 | throw new MongoRuntimeError('OP_MSG Payload Type 1 detected unsupported protocol'); |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | this.parsed = true; |
| 739 | |
| 740 | return this.sections[0]; |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | const MESSAGE_HEADER_SIZE = 16; |
nothing calls this directly
no test coverage detected