@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
36 lines (35 loc) • 967 B
TypeScript
import { IEvent } from "ste-events";
/**
* Parses the Minecraft debug protocol message stream.
*
* The protocol uses length-prefixed messages:
* - 8 hex digits for length + newline (9 bytes total)
* - JSON message body + newline
*
* Example:
* ```
* 00000042\n
* {"type":"event","event":{"type":"StatEvent2",...}}\n
* ```
*/
export default class DebugMessageStreamParser {
private _buffer;
private _expectedLength;
private _onMessage;
private _onError;
get onMessage(): IEvent<DebugMessageStreamParser, unknown>;
get onError(): IEvent<DebugMessageStreamParser, Error>;
/**
* Feed data from the socket into the parser.
*/
write(data: Buffer): void;
/**
* Process the buffer and extract a complete message if available.
* Returns true if a message was processed (and we should continue checking).
*/
private _processBuffer;
/**
* Reset the parser state.
*/
reset(): void;
}