class Transit::Marshaler::BaseJson
Public Class Methods
new(io, opts)
click to toggle source
# File lib/transit/marshaler/cruby/json.rb, line 22 def initialize(io, opts) @oj = Oj::StreamWriter.new(io,opts.delete(:oj_opts) || {}) @state = [] @max_int = JSON_MAX_INT @min_int = JSON_MIN_INT @prefer_strings = true parse_options(opts) end
Public Instance Methods
emit_array_end()
click to toggle source
# File lib/transit/marshaler/cruby/json.rb, line 36 def emit_array_end @state.pop @oj.pop end
emit_array_start(size)
click to toggle source
# File lib/transit/marshaler/cruby/json.rb, line 31 def emit_array_start(size) @state << :array @oj.push_array end
emit_int(tag, i, as_map_key, cache)
click to toggle source
# File lib/transit/marshaler/cruby/json.rb, line 51 def emit_int(tag, i, as_map_key, cache) if as_map_key || i > @max_int || i < @min_int emit_string(ESC, tag, i, as_map_key, cache) else emit_value(i, as_map_key) end end
emit_map_end()
click to toggle source
# File lib/transit/marshaler/cruby/json.rb, line 46 def emit_map_end @state.pop @oj.pop end
emit_map_start(size)
click to toggle source
# File lib/transit/marshaler/cruby/json.rb, line 41 def emit_map_start(size) @state << :map @oj.push_object end
emit_value(obj, as_map_key=false)
click to toggle source
# File lib/transit/marshaler/cruby/json.rb, line 59 def emit_value(obj, as_map_key=false) if @state.last == :array @oj.push_value(obj) else as_map_key ? @oj.push_key(obj) : @oj.push_value(obj) end end
flush()
click to toggle source
# File lib/transit/marshaler/cruby/json.rb, line 67 def flush # no-op end