()
| 431 | } |
| 432 | } |
| 433 | #processRawBuffer() { |
| 434 | // This method is called when it is known that there is at least one message |
| 435 | let bufferHead = this.#rawBuffer[0]; |
| 436 | let headerIndex = bufferHead.indexOf(v8Header); |
| 437 | let nonSerialized = new FastBuffer(); |
| 438 | |
| 439 | while (bufferHead && headerIndex !== 0) { |
| 440 | const nonSerializedData = headerIndex === -1 ? |
| 441 | bufferHead : |
| 442 | bufferHead.slice(0, headerIndex); |
| 443 | nonSerialized = Buffer.concat([nonSerialized, nonSerializedData]); |
| 444 | this.#rawBufferSize -= TypedArrayPrototypeGetLength(nonSerializedData); |
| 445 | if (headerIndex === -1) { |
| 446 | ArrayPrototypeShift(this.#rawBuffer); |
| 447 | } else { |
| 448 | this.#rawBuffer[0] = TypedArrayPrototypeSubarray(bufferHead, headerIndex); |
| 449 | } |
| 450 | bufferHead = this.#rawBuffer[0]; |
| 451 | headerIndex = bufferHead?.indexOf(v8Header); |
| 452 | } |
| 453 | |
| 454 | if (TypedArrayPrototypeGetLength(nonSerialized) > 0) { |
| 455 | this.addToReport({ |
| 456 | __proto__: null, |
| 457 | type: 'test:stdout', |
| 458 | data: { __proto__: null, file: this.name, message: nonSerialized.toString('utf-8') }, |
| 459 | }); |
| 460 | } |
| 461 | |
| 462 | while (bufferHead?.length >= kSerializedSizeHeader) { |
| 463 | // We call `readUInt32BE` manually here, because this is faster than first converting |
| 464 | // it to a buffer and using `readUInt32BE` on that. |
| 465 | const fullMessageSize = ( |
| 466 | bufferHead[kV8HeaderLength] << 24 | |
| 467 | bufferHead[kV8HeaderLength + 1] << 16 | |
| 468 | bufferHead[kV8HeaderLength + 2] << 8 | |
| 469 | bufferHead[kV8HeaderLength + 3] |
| 470 | ) + kSerializedSizeHeader; |
| 471 | |
| 472 | if (this.#rawBufferSize < fullMessageSize) break; |
| 473 | |
| 474 | const concatenatedBuffer = this.#rawBuffer.length === 1 ? |
| 475 | this.#rawBuffer[0] : Buffer.concat(this.#rawBuffer, this.#rawBufferSize); |
| 476 | |
| 477 | const deserializer = new DefaultDeserializer( |
| 478 | TypedArrayPrototypeSubarray(concatenatedBuffer, kSerializedSizeHeader, fullMessageSize), |
| 479 | ); |
| 480 | |
| 481 | bufferHead = TypedArrayPrototypeSubarray(concatenatedBuffer, fullMessageSize); |
| 482 | this.#rawBufferSize = TypedArrayPrototypeGetLength(bufferHead); |
| 483 | this.#rawBuffer = this.#rawBufferSize !== 0 ? [bufferHead] : []; |
| 484 | |
| 485 | deserializer.readHeader(); |
| 486 | const item = deserializer.readValue(); |
| 487 | this.addToReport(item); |
| 488 | } |
| 489 | } |
| 490 | } |
no test coverage detected