class FFI_Yajl::Encoder

def encode(obj)

def encode(obj)
  # initialization that we can do in pure ruby
  yajl_gen_opts = {}
  yajl_gen_opts[:yajl_gen_validate_utf8] = @opts[:validate_utf8] == false ? false : true
  yajl_gen_opts[:yajl_gen_beautify] = false
  yajl_gen_opts[:yajl_gen_indent_string] = " "
  if opts[:pretty]
    yajl_gen_opts[:yajl_gen_beautify] = true
    yajl_gen_opts[:yajl_gen_indent_string] = opts[:indent] ? opts[:indent] : "  "
  end
  # call either the ext or ffi hook
  str = do_yajl_encode(obj, yajl_gen_opts, opts)
  # we can skip cleaning the whole string for utf-8 issues if we have yajl validate as we go
  str.force_encoding("UTF-8")
  unless yajl_gen_opts[:yajl_gen_validate_utf8]
    if str.respond_to?(:scrub)
      str.scrub!
    else
      str.encode!("UTF-16le", undef: :replace, invalid: :replace).encode!("UTF-8")
    end
  end
  str
end