parse(chunk) {
        // Append new chunk to existing buffer
        const newBuffer = new Uint8Array(this.buffer.length + chunk.length);
        newBuffer.set(this.buffer);
        newBuffer.set(chunk, this.buffer.length);
        this.buffer = newBuffer;

        const messages = [];

        while (this.buffer.length >= 16) { // Minimum message size is 16 bytes
            // Read total length (4 bytes)
            const totalLength = this.readInt32(0);

            if (this.buffer.length < totalLength) {
                console.log(this.buffer.length, totalLength);
                break; // Wait for more data
            }

            // Read headers length (4 bytes)
            const headersLength = this.readInt32(4);

            // Parse headers
            const headers = this.parseHeaders(12, headersLength);

            // Calculate payload start and length
            const payloadStart = 12 + headersLength;
            const payloadLength = totalLength - headersLength - 16; // 16 = prelude (8) + checksum (4) + message checksum (4)

            // Extract payload
            const payload = this.buffer.slice(payloadStart, payloadStart + payloadLength);

            // Create message object
            const message = {
                headers,
                payload: this.decodePayload(payload, headers)
            };

            messages.push(message);

            // Remove processed message from buffer
            this.buffer = this.buffer.slice(totalLength);
        }

        return messages;
    }
Parse an EventStream message from a Uint8Array or Buffer
@param {Uint8Array|Buffer} chunk - Raw binary data chunk
@returns {Array} Array of parsed messages