Class: Hash

Inherits:
Object show all
Defined in:
lib/ffi_yajl/json_gem.rb,
lib/ffi_yajl/ffi/encoder.rb

Instance Method Summary collapse

Instance Method Details

#ffi_yajl(yajl_gen, state) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'ext/ffi_yajl/ext/encoder/encoder.c', line 74

def ffi_yajl(yajl_gen, state)
  if ( status = FFI_Yajl.yajl_gen_map_open(yajl_gen) ) != 0
    FFI_Yajl::Encoder.raise_error_for_status(status)
  end
  self.each do |key, value|
    # Perf Fix: mutate state hash rather than creating new copy
    state[:processing_key] = true
    key.ffi_yajl(yajl_gen, state)
    state[:processing_key] = false
    value.ffi_yajl(yajl_gen, state)
  end
  if ( status = FFI_Yajl.yajl_gen_map_close(yajl_gen) ) != 0
    FFI_Yajl::Encoder.raise_error_for_status(status)
  end
end

#to_json(*opts, &block) ⇒ Object



63
64
65
# File 'lib/ffi_yajl/json_gem.rb', line 63

def to_json(*opts, &block)
  FFI_Yajl::Encoder.encode(self)
end