Class: Integer

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



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'ext/ffi_yajl/ext/encoder/encoder.c', line 290

def ffi_yajl(yajl_gen, state)
  str = to_s
  if str == "NaN" || str == "Infinity" || str == "-Infinity"
    raise ::FFI_Yajl::EncodeError, "'#{str}' is an invalid number"
  end

  if state[:processing_key]
    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_number(yajl_gen, str, str.bytesize) ) != 0
      FFI_Yajl::Encoder.raise_error_for_status(status, str)
    end
  end
end