class JsonRpc::DocumentStream
- JsonRpc::DocumentStream
- Reference
- Object
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.crConstant Summary
-
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
Instance Method Summary
-
#io : IO
Backing
IO
stream -
#read_document(max_size : Int = DEFAULT_MAX_SIZE) : String
Reads a single document from the stream.
-
#send_document(document : String)
Sends document, making sure a new-line is followed by it.
Constructor Detail
Instance Method Detail
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