class Gapic::Rest::ServerStream
def next_json! chunk
-
chunk
(String
) -- Contains (partial) JSON object
def next_json! chunk chunk.chars.each do |char| # Invariant: @obj is always either a part of a single JSON object or the entire JSON object. # Hence, it's safe to strip whitespace, commans and array brackets. These characters # are only added before @obj is a complete JSON object and essentially can be flushed. next if @obj.empty? && char != "{" @obj += char next unless char == "}" begin # Two choices here: append a Ruby object into # ready_objs or a string. Going with the latter here. JSON.parse @obj @ready_objs.append @obj @obj = "" rescue JSON::ParserError next end end end