Class: Serialbench::Serializers::Json::StreamHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/serialbench/serializers/json/oj_serializer.rb

Overview

Stream handler for Oj SAJ parsing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ StreamHandler

Returns a new instance of StreamHandler.



73
74
75
76
# File 'lib/serialbench/serializers/json/oj_serializer.rb', line 73

def initialize(&block)
  @block = block
  @result = nil
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



71
72
73
# File 'lib/serialbench/serializers/json/oj_serializer.rb', line 71

def result
  @result
end

Instance Method Details

#add_value(value, key) ⇒ Object



94
95
96
# File 'lib/serialbench/serializers/json/oj_serializer.rb', line 94

def add_value(value, key)
  @block&.call(:value, { key: key, value: value })
end

#array_end(key) ⇒ Object



90
91
92
# File 'lib/serialbench/serializers/json/oj_serializer.rb', line 90

def array_end(key)
  @block&.call(:array_end, key)
end

#array_start(key) ⇒ Object



86
87
88
# File 'lib/serialbench/serializers/json/oj_serializer.rb', line 86

def array_start(key)
  @block&.call(:array_start, key)
end

#hash_end(key) ⇒ Object



82
83
84
# File 'lib/serialbench/serializers/json/oj_serializer.rb', line 82

def hash_end(key)
  @block&.call(:hash_end, key)
end

#hash_start(key) ⇒ Object



78
79
80
# File 'lib/serialbench/serializers/json/oj_serializer.rb', line 78

def hash_start(key)
  @block&.call(:hash_start, key)
end