Class: Transit::Marshaler::BaseJson
- Inherits:
-
Object
- Object
- Transit::Marshaler::BaseJson
show all
- Includes:
- Base
- Defined in:
- lib/transit/marshaler/cruby/json.rb
Instance Method Summary
collapse
Methods included from Base
#emit_array, #emit_boolean, #emit_double, #emit_encoded, #emit_int, #emit_map, #emit_nil, #emit_string, #emit_tagged_value, #escape, #find_handler, #marshal, #marshal_top, #parse_options, #verbose_handlers
Constructor Details
#initialize(io, opts) ⇒ BaseJson
Returns a new instance of BaseJson.
28
29
30
31
32
|
# File 'lib/transit/marshaler/cruby/json.rb', line 28
def initialize(io, opts)
@oj = Oj::StreamWriter.new(io,opts.delete(:oj_opts) || {})
parse_options(default_opts.merge(opts))
@state = []
end
|
Instance Method Details
#default_opts ⇒ Object
22
23
24
25
26
|
# File 'lib/transit/marshaler/cruby/json.rb', line 22
def default_opts
{:prefer_strings => true,
:max_int => JSON_MAX_INT,
:min_int => JSON_MIN_INT}
end
|
#emit_array_end ⇒ Object
39
40
41
42
|
# File 'lib/transit/marshaler/cruby/json.rb', line 39
def emit_array_end
@state.pop
@oj.pop
end
|
#emit_array_start(size) ⇒ Object
34
35
36
37
|
# File 'lib/transit/marshaler/cruby/json.rb', line 34
def emit_array_start(size)
@state << :array
@oj.push_array
end
|
#emit_map_end ⇒ Object
49
50
51
52
|
# File 'lib/transit/marshaler/cruby/json.rb', line 49
def emit_map_end
@state.pop
@oj.pop
end
|
#emit_map_start(size) ⇒ Object
44
45
46
47
|
# File 'lib/transit/marshaler/cruby/json.rb', line 44
def emit_map_start(size)
@state << :map
@oj.push_object
end
|
#emit_value(obj, as_map_key = false) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/transit/marshaler/cruby/json.rb', line 54
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 ⇒ Object
62
63
64
|
# File 'lib/transit/marshaler/cruby/json.rb', line 62
def flush
end
|