class

JsonRpc::DocumentStream

Inherits Reference / Object

Streams JSON documents from and into an IO stream.

Uses a new-line ("\n") when sending. Doesn't require it when receiving.

Constants

BUFFER_SIZE = 1024

Size of the read buffer

DEFAULT_MAX_SIZE = 1024 ** 2

Maximum document size (1 MiB)

Constructors

new(io : IO)

Constructs a reader with backing device io

Source

Instance methods

io

Backing IO stream

Source
read_document(max_size : Int = DEFAULT_MAX_SIZE) : String

Reads a single document from the stream.

A document begins with a opening brace, and ends with a balancing closing one.

Note: The result may not be valid JSON. The algorithm only tries to find the end of a valid JSON document: If it's not valid, the result may be neither.

ameba:disable Metrics/CyclomaticComplexity

Source
send_document(document : String)

Sends document, making sure a new-line is followed by it.

Source

Nested types