class JsonRpc::DocumentStream

Overview

Streams JSON documents from and into an IO stream.

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

Defined in:

json_rpc/document_stream.cr

Constant Summary

BUFFER_SIZE = 1024

Size of the read buffer

DEFAULT_MAX_SIZE = 1024 ** 2

Maximum document size (1 MiB)

Constructors

Instance Method Summary

Constructor Detail

def self.new(io : IO) #

Constructs a reader with backing device io


[View source]

Instance Method Detail

def io : IO #

Backing IO stream


[View source]
def 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


[View source]
def send_document(document : String) #

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


[View source]