Class: Hash

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

Instance Method Summary collapse

Instance Method Details

#ffi_yajl(rb_yajl_gen, state) ⇒ Object

<Object>#to_ffi_yajl() method calls



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'ext/ffi_yajl/ext/encoder/encoder.c', line 214

def ffi_yajl(yajl_gen, state)
  if state[:processing_key]
    str = to_s
    if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
      FFI_Yajl::Encoder.raise_error_for_status(status, str)
    end
  else
    if ( status = FFI_Yajl.yajl_gen_map_open(yajl_gen) ) != 0
      FFI_Yajl::Encoder.raise_error_for_status(status, "{")
    end
    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
end