diff options
| author | frsyuki <frsyuki@users.sourceforge.jp> | 2010-04-17 16:16:56 +0900 |
|---|---|---|
| committer | frsyuki <frsyuki@users.sourceforge.jp> | 2010-04-17 16:16:56 +0900 |
| commit | a55affe4d5bce92ee692fd80b10365b6ec49804c (patch) | |
| tree | 39b3942cc74e8e04c1a484871c2afde0b0738887 /ruby | |
| parent | a6ec726ed7ca72662f0abbc8e1d8e361201483ae (diff) | |
| download | msgpack-python-a55affe4d5bce92ee692fd80b10365b6ec49804c.tar.gz | |
ruby: add Symbol#to_msgpack
Diffstat (limited to 'ruby')
| -rw-r--r-- | ruby/pack.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/ruby/pack.c b/ruby/pack.c index 1d0068c..387bab6 100644 --- a/ruby/pack.c +++ b/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); } |
