Class: ObjectStream::JsonStream
- Inherits:
-
Object
- Object
- ObjectStream::JsonStream
- Includes:
- ObjectStream
- Defined in:
- lib/object-stream.rb
Constant Summary collapse
- DEFAULT_CHUNK_SIZE =
2000
Constants included from ObjectStream
DEFAULT_MAX_OUTBOX, JSON_TYPE, MARSHAL_TYPE, MSGPACK_TYPE, TYPES, VERSION, YAML_TYPE
Instance Attribute Summary collapse
-
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
Attributes included from ObjectStream
Instance Method Summary collapse
-
#initialize(io, chunk_size: DEFAULT_CHUNK_SIZE) ⇒ JsonStream
constructor
A new instance of JsonStream.
-
#read_from_stream(&bl) ⇒ Object
Blocks only if no data available on io.
- #write_to_stream(object) ⇒ Object
Methods included from ObjectStream
#close, #closed?, #each, #eof?, #flush_buffer, #flush_outbox, new, #read, #read_one, register_type, stream_class_for, #to_io, #to_s, #write, #write_to_buffer, #write_to_outbox
Constructor Details
#initialize(io, chunk_size: DEFAULT_CHUNK_SIZE) ⇒ JsonStream
Returns a new instance of JsonStream.
239 240 241 242 243 244 |
# File 'lib/object-stream.rb', line 239 def initialize io, chunk_size: DEFAULT_CHUNK_SIZE super @parser = Yajl::Parser.new @encoder = Yajl::Encoder.new @chunk_size = chunk_size end |
Instance Attribute Details
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
235 236 237 |
# File 'lib/object-stream.rb', line 235 def chunk_size @chunk_size end |
Instance Method Details
#read_from_stream(&bl) ⇒ Object
Blocks only if no data available on io.
247 248 249 250 |
# File 'lib/object-stream.rb', line 247 def read_from_stream(&bl) @parser.on_parse_complete = bl @parser << io.readpartial(chunk_size) end |
#write_to_stream(object) ⇒ Object
252 253 254 255 |
# File 'lib/object-stream.rb', line 252 def write_to_stream object @encoder.encode object, io self end |