示例#1
0
/*
 * 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;
}
示例#2
0
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);
}
示例#3
0
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;
  }
}
示例#4
0
/*
 * 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;
}