/* * Document-method: Fixnum#to_msgpack * * call-seq: * fixnum.to_msgpack(out = '') -> String * * Serializes the Fixnum into raw bytes. */ static VALUE MessagePack_Fixnum_to_msgpack(int argc, VALUE *argv, VALUE self) { ARG_BUFFER(out, argc, argv); #ifdef JRUBY msgpack_pack_long(out, FIXNUM_P(self) ? FIX2LONG(self) : rb_num2ll(self)); #else msgpack_pack_long(out, FIX2LONG(self)); #endif return out; }
static inline void pack_integer(msgpack_packer *pk, const char *int_token) { char *end; long value; errno = 0; value = strtol(int_token, &end, 10); /* TODO: error handling */ /* TODO */ msgpack_pack_long(pk, value); }
static void pack_value_object(msgpack_packer *packer, VALUE value) { VALUE rubyString; char *keyString; switch (TYPE(value)) { case T_FIXNUM: msgpack_pack_long(packer, FIX2LONG(value)); break; case T_FLOAT: msgpack_pack_double(packer, rb_num2dbl(value)); break; default: rubyString = rb_funcall(value, rb_intern("to_s"), 0, 0); keyString = StringValueCStr(rubyString); pack_string(packer, keyString); break; } }
/* * Document-method: Fixnum#to_msgpack * * call-seq: * fixnum.to_msgpack(out = '') -> String * * Serializes the Fixnum into raw bytes. */ static VALUE MessagePack_Fixnum_to_msgpack(int argc, VALUE *argv, VALUE self) { ARG_BUFFER(out, argc, argv); msgpack_pack_long(out, FIX2LONG(self)); return out; }