text: #include <ruby.h>
  
  // This function is defined in Rust
  extern VALUE process_payload(VALUE payload, VALUE options, VALUE data);
  void Init_native_extensions(void);
  VALUE to_h(VALUE self, VALUE payload, VALUE options);
  
  /* This function is the Ruby entry point for the extensions.
   * Any extension has to have a function named Init_<name> which will be
   * called when the extension is required. P.S. Remember that you need to have
   * the ext directory in your load path to require an extension.
   *
   * This function overrides the `__to_h` method on the Serializable plugin's
   * class methods. I.E. Every time `__to_h` gets called on ObjectSerializer this
   * function is invoked to process the call.
   */
  void
  Init_native_extensions(void) {
    VALUE mFastJson;
    VALUE mPlugins;
    VALUE mObjectSerializer;
    VALUE mSerializable;
    VALUE mClassMethods;
  
    mFastJson = rb_const_get(rb_cObject, rb_intern("FasterJsonapi"));
    mPlugins = rb_const_get(mFastJson, rb_intern("Plugins"));
    mObjectSerializer = rb_const_get(mPlugins, rb_intern("ObjectSerializer"));
    mSerializable = rb_const_get(mObjectSerializer, rb_intern("Serializable"));
    mClassMethods = rb_const_get(mSerializable, rb_intern("ClassMethods"));
  
    rb_define_method(
        mClassMethods,
        "__to_h",
        RUBY_METHOD_FUNC(to_h),
        2
    );
  }
  
  VALUE
  to_h(VALUE self, VALUE payload, VALUE options) {
    VALUE mFastJson;
    VALUE mObjectSerializer;
    VALUE oData;
  
    mFastJson = rb_const_get(rb_cObject, rb_intern("FasterJsonapi"));
    mObjectSerializer = rb_const_get(mFastJson, rb_intern("ObjectSerializer"));
  
    oData = rb_funcall(mObjectSerializer, rb_intern("__faster_jsonapi_data"), 0);
  
    process_payload(payload, options, oData);
  
    return payload;
  }
  