Class: Rjq::JSON::StreamParser

Inherits:
Object
  • Object
show all
Defined in:
lib/rjq/json/stream_parser.rb

Defined Under Namespace

Classes: ParsedEvent, Result, StreamError

Constant Summary collapse

DEFAULT_MAX_DEPTH =
256

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, seq: false, stream_errors: false, chunk_size: InputBuffer::DEFAULT_CHUNK_SIZE, on_error: nil, max_depth: DEFAULT_MAX_DEPTH, max_number_digits: nil, max_string_bytes: nil, locations: false) ⇒ StreamParser

Returns a new instance of StreamParser.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rjq/json/stream_parser.rb', line 28

def initialize(input, seq: false, stream_errors: false, chunk_size: InputBuffer::DEFAULT_CHUNK_SIZE,
               on_error: nil, max_depth: DEFAULT_MAX_DEPTH, max_number_digits: nil, max_string_bytes: nil,
               locations: false)
  validate_options!(chunk_size, max_depth, max_number_digits, max_string_bytes)
  @input = InputBuffer.new(input, chunk_size: chunk_size)
  @seq = seq
  @stream_errors = stream_errors
  @on_error = on_error
  @max_depth = max_depth
  @max_number_digits = max_number_digits
  @max_string_bytes = max_string_bytes
  @locations = locations
  @depth = 0
  @index = 0
  @line = 1
  @column = 1
  advance if current == "\uFEFF"
end

Class Method Details

.parse(io_or_string, seq: false, stream_errors: false, chunk_size: InputBuffer::DEFAULT_CHUNK_SIZE, on_error: nil, max_depth: DEFAULT_MAX_DEPTH, max_number_digits: nil, max_string_bytes: nil, locations: false) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/rjq/json/stream_parser.rb', line 19

def parse(io_or_string, seq: false, stream_errors: false, chunk_size: InputBuffer::DEFAULT_CHUNK_SIZE,
          on_error: nil, max_depth: DEFAULT_MAX_DEPTH, max_number_digits: nil, max_string_bytes: nil,
          locations: false)
  new(io_or_string, seq: seq, stream_errors: stream_errors, chunk_size: chunk_size,
                    on_error: on_error, max_depth: max_depth, max_number_digits: max_number_digits,
                    max_string_bytes: max_string_bytes, locations: locations).parse
end

Instance Method Details

#parseObject



47
48
49
50
51
52
# File 'lib/rjq/json/stream_parser.rb', line 47

def parse
  Enumerator.new do |yielder|
    @events = yielder
    parse_values
  end
end