Skip to content

lspeasy / core/src / parseMessage

Function: parseMessage()

ts
function parseMessage(buffer): 
  | {
  bytesRead: number;
  message: Message;
}
  | null;

Defined in: packages/core/src/jsonrpc/framing.ts:72

Parses a single framed JSON-RPC 2.0 message from a raw byte buffer.

Parameters

ParameterTypeDescription
bufferBufferRaw byte buffer that may contain one or more framed messages.

Returns

| { bytesRead: number; message: Message; } | null

An object with the parsed message and bytesRead, or null if the buffer does not yet contain a complete framed message.

Remarks

This is the low-level framing parser used internally by Node.js transports (StdioTransport, TcpTransport). The buffer may contain partial data; null is returned when more bytes are needed.

The framing format is the LSP base protocol: Content-Length: <n>\r\n\r\n<json-body>.

Throws

If Content-Length is missing or the JSON body cannot be parsed.

Released under the MIT License.