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.



58
59
60
61
# File 'lib/serialbench/serializers/json/oj_serializer.rb', line 58

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

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



56
57
58
# File 'lib/serialbench/serializers/json/oj_serializer.rb', line 56

def result
  @result
end

Instance Method Details

#add_value(value, key) ⇒ Object



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

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

#array_end(key) ⇒ Object



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

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

#array_start(key) ⇒ Object



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

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

#hash_end(key) ⇒ Object



67
68
69
# File 'lib/serialbench/serializers/json/oj_serializer.rb', line 67

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

#hash_start(key) ⇒ Object



63
64
65
# File 'lib/serialbench/serializers/json/oj_serializer.rb', line 63

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