mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-06 17:59:52 +00:00
ruby: add Symbol#to_msgpack
This commit is contained in:
parent
a6ec726ed7
commit
a55affe4d5
1 changed files with 11 additions and 0 deletions
11
ruby/pack.c
11
ruby/pack.c
|
|
@ -112,6 +112,16 @@ static VALUE MessagePack_String_to_msgpack(int argc, VALUE *argv, VALUE self)
|
|||
return out;
|
||||
}
|
||||
|
||||
static VALUE MessagePack_Symbol_to_msgpack(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
ARG_BUFFER(out, argc, argv);
|
||||
const char* name = rb_id2name(SYM2ID(self));
|
||||
size_t len = strlen(name);
|
||||
msgpack_pack_raw(out, len);
|
||||
msgpack_pack_raw_body(out, name, len);
|
||||
return out;
|
||||
}
|
||||
|
||||
static VALUE MessagePack_Array_to_msgpack(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
ARG_BUFFER(out, argc, argv);
|
||||
|
|
@ -172,6 +182,7 @@ void Init_msgpack_pack(VALUE mMessagePack)
|
|||
rb_define_method_id(rb_cString, s_to_msgpack, MessagePack_String_to_msgpack, -1);
|
||||
rb_define_method_id(rb_cArray, s_to_msgpack, MessagePack_Array_to_msgpack, -1);
|
||||
rb_define_method_id(rb_cHash, s_to_msgpack, MessagePack_Hash_to_msgpack, -1);
|
||||
rb_define_method_id(rb_cSymbol, s_to_msgpack, MessagePack_Symbol_to_msgpack, -1);
|
||||
rb_define_module_function(mMessagePack, "pack", MessagePack_pack, -1);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue