msgpack 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,16 +7,12 @@ config/requirements.rb
7
7
  ext/extconf.rb
8
8
  ext/pack.c
9
9
  ext/pack.h
10
- ext/pack_inline.h
11
10
  ext/rbinit.c
12
11
  ext/unpack.c
13
12
  ext/unpack.h
14
- ext/unpack_context.h
15
- ext/unpack_inline.c
16
- msgpack/pack/inline_context.h
17
- msgpack/pack/inline_impl.h
18
- msgpack/unpack/inline_context.h
19
- msgpack/unpack/inline_impl.h
13
+ msgpack/pack_template.h
14
+ msgpack/unpack_define.h
15
+ msgpack/unpack_template.h
20
16
  lib/msgpack/version.rb
21
17
  script/console
22
18
  script/destroy
data/README.txt CHANGED
@@ -1,8 +1,11 @@
1
- MessagePack
2
- -----------
1
+ =MessagePack
2
+
3
+ == DESCRIPTION:
4
+
3
5
  Binary-based efficient data interchange format.
4
6
 
5
7
 
8
+ == LICENSE:
6
9
 
7
10
  Copyright (C) 2008 FURUHASHI Sadayuki
8
11
 
@@ -1,4 +1,4 @@
1
1
  require 'mkmf'
2
- $CFLAGS << " -I.. -Wall -O9"
2
+ $CFLAGS << " -I.. -Wall -O4"
3
3
  create_makefile('msgpack')
4
4
 
data/ext/pack.c CHANGED
@@ -15,7 +15,42 @@
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
17
  */
18
- #include "pack_inline.h"
18
+ #include "ruby.h"
19
+ #include <stddef.h>
20
+ #include <stdint.h>
21
+
22
+ #define msgpack_pack_inline_func(name) \
23
+ static void msgpack_pack_##name
24
+
25
+ #define msgpack_pack_user VALUE
26
+
27
+ #define msgpack_pack_append_buffer(user, buf, len) \
28
+ rb_str_buf_cat(user, (const void*)buf, len)
29
+
30
+ /*
31
+ static void msgpack_pack_int(VALUE x, int d);
32
+ static void msgpack_pack_unsigned_int(VALUE x, unsigned int d);
33
+ static void msgpack_pack_uint8(VALUE x, uint8_t d);
34
+ static void msgpack_pack_uint16(VALUE x, uint16_t d);
35
+ static void msgpack_pack_uint32(VALUE x, uint32_t d);
36
+ static void msgpack_pack_uint64(VALUE x, uint64_t d);
37
+ static void msgpack_pack_int8(VALUE x, int8_t d);
38
+ static void msgpack_pack_int16(VALUE x, int16_t d);
39
+ static void msgpack_pack_int32(VALUE x, int32_t d);
40
+ static void msgpack_pack_int64(VALUE x, int64_t d);
41
+ static void msgpack_pack_float(VALUE x, float d);
42
+ static void msgpack_pack_double(VALUE x, double d);
43
+ static void msgpack_pack_nil(VALUE x);
44
+ static void msgpack_pack_true(VALUE x);
45
+ static void msgpack_pack_false(VALUE x);
46
+ static void msgpack_pack_array(VALUE x, unsigned int n);
47
+ static void msgpack_pack_map(VALUE x, unsigned int n);
48
+ static void msgpack_pack_raw(VALUE x, size_t l);
49
+ static void msgpack_pack_raw_body(VALUE x, const void* b, size_t l);
50
+ */
51
+
52
+ #include "msgpack/pack_template.h"
53
+
19
54
 
20
55
  #ifndef RUBY_VM
21
56
  #include "st.h" // ruby hash
@@ -62,6 +97,23 @@ static VALUE MessagePack_Fixnum_to_msgpack(int argc, VALUE *argv, VALUE self)
62
97
  return out;
63
98
  }
64
99
 
100
+
101
+ #ifndef RBIGNUM_SIGN // Ruby 1.8
102
+ #define RBIGNUM_SIGN(b) (RBIGNUM(b)->sign)
103
+ #endif
104
+
105
+ static VALUE MessagePack_Bignum_to_msgpack(int argc, VALUE *argv, VALUE self)
106
+ {
107
+ ARG_BUFFER(out, argc, argv);
108
+ // FIXME bignum
109
+ if(RBIGNUM_SIGN(self)) { // positive
110
+ msgpack_pack_uint64(out, rb_big2ull(self));
111
+ } else { // negative
112
+ msgpack_pack_int64(out, rb_big2ll(self));
113
+ }
114
+ return out;
115
+ }
116
+
65
117
  static VALUE MessagePack_Float_to_msgpack(int argc, VALUE *argv, VALUE self)
66
118
  {
67
119
  ARG_BUFFER(out, argc, argv);
@@ -72,7 +124,8 @@ static VALUE MessagePack_Float_to_msgpack(int argc, VALUE *argv, VALUE self)
72
124
  static VALUE MessagePack_String_to_msgpack(int argc, VALUE *argv, VALUE self)
73
125
  {
74
126
  ARG_BUFFER(out, argc, argv);
75
- msgpack_pack_raw(out, RSTRING_PTR(self), RSTRING_LEN(self));
127
+ msgpack_pack_raw(out, RSTRING_LEN(self));
128
+ msgpack_pack_raw_body(out, RSTRING_PTR(self), RSTRING_LEN(self));
76
129
  return out;
77
130
  }
78
131
 
@@ -122,6 +175,7 @@ void Init_msgpack_pack(VALUE mMessagePack)
122
175
  rb_define_method_id(rb_cTrueClass, s_to_msgpack, MessagePack_TrueClass_to_msgpack, -1);
123
176
  rb_define_method_id(rb_cFalseClass, s_to_msgpack, MessagePack_FalseClass_to_msgpack, -1);
124
177
  rb_define_method_id(rb_cFixnum, s_to_msgpack, MessagePack_Fixnum_to_msgpack, -1);
178
+ rb_define_method_id(rb_cBignum, s_to_msgpack, MessagePack_Bignum_to_msgpack, -1);
125
179
  rb_define_method_id(rb_cFloat, s_to_msgpack, MessagePack_Float_to_msgpack, -1);
126
180
  rb_define_method_id(rb_cString, s_to_msgpack, MessagePack_String_to_msgpack, -1);
127
181
  rb_define_method_id(rb_cArray, s_to_msgpack, MessagePack_Array_to_msgpack, -1);
@@ -16,8 +16,99 @@
16
16
  * limitations under the License.
17
17
  */
18
18
  #include "ruby.h"
19
- #include "unpack_context.h"
20
- #include <stdio.h>
19
+ #include "msgpack/unpack_define.h"
20
+
21
+
22
+ typedef struct {
23
+ int finished;
24
+ } msgpack_unpack_context;
25
+
26
+
27
+ #define msgpack_unpack_struct(name) \
28
+ struct msgpack_unpacker_##name
29
+
30
+ #define msgpack_unpack_func(ret, name) \
31
+ ret msgpack_unpacker_##name
32
+
33
+ #define msgpack_unpack_callback(name) \
34
+ template_callback_##name
35
+
36
+ #define msgpack_unpack_object VALUE
37
+
38
+ #define msgpack_unpack_user msgpack_unpack_context
39
+
40
+
41
+ struct msgpack_unpacker_context;
42
+ typedef struct msgpack_unpacker_context msgpack_unpacker;
43
+
44
+ static void msgpack_unpacker_init(msgpack_unpacker* ctx);
45
+
46
+ static VALUE msgpack_unpacker_data(msgpack_unpacker* ctx);
47
+
48
+ static int msgpack_unpacker_execute(msgpack_unpacker* ctx,
49
+ const char* data, size_t len, size_t* off);
50
+
51
+
52
+ static inline VALUE template_callback_init(msgpack_unpack_context* x)
53
+ { return Qnil; }
54
+
55
+ static inline VALUE template_callback_uint8(msgpack_unpack_context* x, uint8_t d)
56
+ { return INT2FIX(d); }
57
+
58
+ static inline VALUE template_callback_uint16(msgpack_unpack_context* x, uint16_t d)
59
+ { return INT2FIX(d); }
60
+
61
+ static inline VALUE template_callback_uint32(msgpack_unpack_context* x, uint32_t d)
62
+ { return UINT2NUM(d); }
63
+
64
+ static inline VALUE template_callback_uint64(msgpack_unpack_context* x, uint64_t d)
65
+ { return rb_ull2inum(d); }
66
+
67
+ static inline VALUE template_callback_int8(msgpack_unpack_context* x, int8_t d)
68
+ { return INT2FIX((long)d); }
69
+
70
+ static inline VALUE template_callback_int16(msgpack_unpack_context* x, int16_t d)
71
+ { return INT2FIX((long)d); }
72
+
73
+ static inline VALUE template_callback_int32(msgpack_unpack_context* x, int32_t d)
74
+ { return INT2NUM((long)d); }
75
+
76
+ static inline VALUE template_callback_int64(msgpack_unpack_context* x, int64_t d)
77
+ { return rb_ll2inum(d); }
78
+
79
+ static inline VALUE template_callback_float(msgpack_unpack_context* x, float d)
80
+ { return rb_float_new(d); }
81
+
82
+ static inline VALUE template_callback_double(msgpack_unpack_context* x, double d)
83
+ { return rb_float_new(d); }
84
+
85
+ static inline VALUE template_callback_nil(msgpack_unpack_context* x)
86
+ { return Qnil; }
87
+
88
+ static inline VALUE template_callback_true(msgpack_unpack_context* x)
89
+ { return Qtrue; }
90
+
91
+ static inline VALUE template_callback_false(msgpack_unpack_context* x)
92
+ { return Qfalse; }
93
+
94
+ static inline VALUE template_callback_array(msgpack_unpack_context* x, unsigned int n)
95
+ { return rb_ary_new2(n); }
96
+
97
+ static inline void template_callback_array_item(msgpack_unpack_context* x, VALUE* c, VALUE o)
98
+ { rb_ary_push(*c, o); } // FIXME set value directry RARRAY_PTR(obj)[RARRAY_LEN(obj)++]
99
+
100
+ static inline VALUE template_callback_map(msgpack_unpack_context* x, unsigned int n)
101
+ { return rb_hash_new(); }
102
+
103
+ static inline void template_callback_map_item(msgpack_unpack_context* x, VALUE* c, VALUE k, VALUE v)
104
+ { rb_hash_aset(*c, k, v); }
105
+
106
+ static inline VALUE template_callback_raw(msgpack_unpack_context* x, const char* b, const char* p, unsigned int l)
107
+ { return rb_str_new(p, l); }
108
+
109
+
110
+ #include "msgpack/unpack_template.h"
111
+
21
112
 
22
113
  #define UNPACKER(from, name) \
23
114
  msgpack_unpacker *name = NULL; \
@@ -45,7 +136,7 @@ static void MessagePack_Unpacker_mark(msgpack_unpacker *mp)
45
136
  unsigned int i;
46
137
  for(i=0; i < mp->top; ++i) {
47
138
  rb_gc_mark(mp->stack[i].obj);
48
- rb_gc_mark(mp->stack[i].tmp.map_key);
139
+ rb_gc_mark(mp->stack[i].map_key);
49
140
  }
50
141
  }
51
142
 
@@ -61,7 +152,7 @@ static VALUE MessagePack_Unpacker_alloc(VALUE klass)
61
152
  static VALUE MessagePack_Unpacker_reset(VALUE self)
62
153
  {
63
154
  UNPACKER(self, mp);
64
- mp->user.finished = false;
155
+ mp->user.finished = 0;
65
156
  msgpack_unpacker_init(mp);
66
157
  return self;
67
158
  }
@@ -85,18 +176,18 @@ static VALUE MessagePack_Unpacker_execute_impl(VALUE args)
85
176
  int ret;
86
177
 
87
178
  if(from >= dlen) {
88
- rb_raise(eUnpackError, "Requested start is after data buffer end.");
179
+ rb_raise(eUnpackError, "offset is bigger than data buffer size.");
89
180
  }
90
181
 
91
182
  ret = msgpack_unpacker_execute(mp, dptr, (size_t)dlen, &from);
92
183
 
93
184
  if(ret < 0) {
94
- rb_raise(eUnpackError, "Parse error.");
185
+ rb_raise(eUnpackError, "parse error.");
95
186
  } else if(ret > 0) {
96
- mp->user.finished = true;
187
+ mp->user.finished = 1;
97
188
  return ULONG2NUM(from);
98
189
  } else {
99
- mp->user.finished = false;
190
+ mp->user.finished = 0;
100
191
  return ULONG2NUM(from);
101
192
  }
102
193
  }
@@ -151,12 +242,12 @@ static VALUE MessagePack_unpack_impl(VALUE args)
151
242
  ret = msgpack_unpacker_execute(mp, dptr, (size_t)dlen, &from);
152
243
 
153
244
  if(ret < 0) {
154
- rb_raise(eUnpackError, "Parse error.");
245
+ rb_raise(eUnpackError, "parse error.");
155
246
  } else if(ret == 0) {
156
- rb_raise(eUnpackError, "Insufficient bytes.");
247
+ rb_raise(eUnpackError, "insufficient bytes.");
157
248
  } else {
158
249
  if(from < dlen) {
159
- rb_raise(eUnpackError, "Extra bytes.");
250
+ rb_raise(eUnpackError, "extra bytes.");
160
251
  }
161
252
  return msgpack_unpacker_data(mp);
162
253
  }
@@ -1,8 +1,8 @@
1
1
  module MessagePack
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 0
5
- TINY = 1
4
+ MINOR = 2
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -1,5 +1,5 @@
1
1
  /*
2
- * MessagePack packing routine
2
+ * MessagePack packing routine template
3
3
  *
4
4
  * Copyright (C) 2008 FURUHASHI Sadayuki
5
5
  *
@@ -15,58 +15,78 @@
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
17
  */
18
- #ifndef MSGPACK_PACK_INLINE_IMPL_H__
19
- #define MSGPACK_PACK_INLINE_IMPL_H__
20
18
 
21
- #include <string.h>
22
- #include <arpa/inet.h>
19
+ #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
20
+ #if __BYTE_ORDER == __LITTLE_ENDIAN
21
+ #define __LITTLE_ENDIAN__
22
+ #elif __BYTE_ORDER == __BIG_ENDIAN
23
+ #define __BIG_ENDIAN__
24
+ #endif
25
+ #endif
23
26
 
24
27
  #ifdef __LITTLE_ENDIAN__
25
28
 
26
- #define STORE_16(d) \
29
+ #define STORE_BE16(d) \
27
30
  ((char*)&d)[1], ((char*)&d)[0]
28
31
 
29
- #define STORE_32(d) \
32
+ #define STORE_BE32(d) \
30
33
  ((char*)&d)[3], ((char*)&d)[2], ((char*)&d)[1], ((char*)&d)[0]
31
34
 
32
- #define STORE_64(d) \
35
+ #define STORE_BE64(d) \
33
36
  ((char*)&d)[7], ((char*)&d)[6], ((char*)&d)[5], ((char*)&d)[4], \
34
37
  ((char*)&d)[3], ((char*)&d)[2], ((char*)&d)[1], ((char*)&d)[0]
35
38
 
36
39
  #elif __BIG_ENDIAN__
37
40
 
38
- #define STORE_16(d) \
39
- ((char*)&d)[2], ((char*)&d)[3]
41
+ #define STORE_BE16(d) \
42
+ ((char*)&d)[0], ((char*)&d)[1]
40
43
 
41
- #define STORE_32(d) \
44
+ #define STORE_BE32(d) \
42
45
  ((char*)&d)[0], ((char*)&d)[1], ((char*)&d)[2], ((char*)&d)[3]
43
46
 
44
- #define STORE_32(d) \
47
+ #define STORE_BE64(d) \
45
48
  ((char*)&d)[0], ((char*)&d)[1], ((char*)&d)[2], ((char*)&d)[3], \
46
49
  ((char*)&d)[4], ((char*)&d)[5], ((char*)&d)[6], ((char*)&d)[7]
47
50
 
48
51
  #endif
49
52
 
50
53
 
54
+ #ifndef msgpack_pack_inline_func
55
+ #error msgpack_pack_inline_func template is not defined
56
+ #endif
57
+
58
+ #ifndef msgpack_pack_user
59
+ #error msgpack_pack_user type is not defined
60
+ #endif
61
+
62
+ #ifndef msgpack_pack_append_buffer
63
+ #error msgpack_pack_append_buffer callback is not defined
64
+ #endif
65
+
66
+
51
67
  /*
52
68
  * Integer
53
69
  */
54
70
 
55
71
  // wrapper
56
- inline void msgpack_pack_int(msgpack_pack_context x, int d)
72
+ msgpack_pack_inline_func(int)(msgpack_pack_user x, int d)
57
73
  {
58
74
  if(d < -32) {
59
- if(d < -32768) { // signed 32
60
- const unsigned char buf[5] = {0xd2, STORE_32(d)};
75
+ if(d < -32768) {
76
+ // signed 32
77
+ const unsigned char buf[5] = {0xd2, STORE_BE32(d)};
61
78
  msgpack_pack_append_buffer(x, buf, 5);
62
- } else if(d < -128) { // signed 16
63
- const unsigned char buf[3] = {0xd1, STORE_16(d)};
79
+ } else if(d < -128) {
80
+ // signed 16
81
+ const unsigned char buf[3] = {0xd1, STORE_BE16(d)};
64
82
  msgpack_pack_append_buffer(x, buf, 3);
65
- } else { // signed 8
83
+ } else {
84
+ // signed 8
66
85
  const unsigned char buf[2] = {0xd0, (uint8_t)d};
67
86
  msgpack_pack_append_buffer(x, buf, 2);
68
87
  }
69
- } else if(d < 128) { // fixnum
88
+ } else if(d < 128) {
89
+ // fixnum
70
90
  msgpack_pack_append_buffer(x, (uint8_t*)&d, 1);
71
91
  } else {
72
92
  if(d < 256) {
@@ -75,38 +95,42 @@ inline void msgpack_pack_int(msgpack_pack_context x, int d)
75
95
  msgpack_pack_append_buffer(x, buf, 2);
76
96
  } else if(d < 65536) {
77
97
  // unsigned 16
78
- const unsigned char buf[3] = {0xcd, STORE_16(d)};
98
+ const unsigned char buf[3] = {0xcd, STORE_BE16(d)};
79
99
  msgpack_pack_append_buffer(x, buf, 3);
80
100
  } else {
81
101
  // unsigned 32
82
- const unsigned char buf[5] = {0xce, STORE_32(d)};
102
+ const unsigned char buf[5] = {0xce, STORE_BE32(d)};
83
103
  msgpack_pack_append_buffer(x, buf, 5);
84
104
  }
85
105
  }
86
106
  }
87
107
 
88
108
  // wrapper
89
- inline void msgpack_pack_unsigned_int(msgpack_pack_context x, unsigned int d)
109
+ msgpack_pack_inline_func(unsigned_int)(msgpack_pack_user x, unsigned int d)
90
110
  {
91
- if(d < 128) {
92
- // fixnum
93
- msgpack_pack_append_buffer(x, (uint8_t*)&d, 1);
94
- } else if(d < 256) {
95
- // unsigned 8
96
- const unsigned char buf[2] = {0xcc, (uint8_t)d};
97
- msgpack_pack_append_buffer(x, buf, 2);
98
- } else if(d < 65536) {
99
- // unsigned 16
100
- const unsigned char buf[3] = {0xcd, STORE_16(d)};
101
- msgpack_pack_append_buffer(x, buf, 3);
111
+ if(d < 256) {
112
+ if(d < 128) {
113
+ // fixnum
114
+ msgpack_pack_append_buffer(x, (unsigned char*)&d, 1);
115
+ } else {
116
+ // unsigned 8
117
+ const unsigned char buf[2] = {0xcc, (uint8_t)d};
118
+ msgpack_pack_append_buffer(x, buf, 2);
119
+ }
102
120
  } else {
103
- // unsigned 32
104
- const unsigned char buf[5] = {0xce, STORE_32(d)};
105
- msgpack_pack_append_buffer(x, buf, 5);
121
+ if(d < 65536) {
122
+ // unsigned 16
123
+ const unsigned char buf[3] = {0xcd, STORE_BE16(d)};
124
+ msgpack_pack_append_buffer(x, buf, 3);
125
+ } else {
126
+ // unsigned 32
127
+ const unsigned char buf[5] = {0xce, STORE_BE32(d)};
128
+ msgpack_pack_append_buffer(x, buf, 5);
129
+ }
106
130
  }
107
131
  }
108
132
 
109
- inline void msgpack_pack_unsigned_int_8(msgpack_pack_context x, uint8_t d)
133
+ msgpack_pack_inline_func(uint8)(msgpack_pack_user x, uint8_t d)
110
134
  {
111
135
  if(d < 128) {
112
136
  msgpack_pack_append_buffer(x, &d, 1);
@@ -116,26 +140,25 @@ inline void msgpack_pack_unsigned_int_8(msgpack_pack_context x, uint8_t d)
116
140
  }
117
141
  }
118
142
 
119
- inline void msgpack_pack_unsigned_int_16(msgpack_pack_context x, uint16_t d)
143
+ msgpack_pack_inline_func(uint16)(msgpack_pack_user x, uint16_t d)
120
144
  {
121
- const unsigned char buf[3] = {0xcd, STORE_16(d)};
145
+ const unsigned char buf[3] = {0xcd, STORE_BE16(d)};
122
146
  msgpack_pack_append_buffer(x, buf, 3);
123
147
  }
124
148
 
125
- inline void msgpack_pack_unsigned_int_32(msgpack_pack_context x, uint32_t d)
149
+ msgpack_pack_inline_func(uint32)(msgpack_pack_user x, uint32_t d)
126
150
  {
127
- const unsigned char buf[5] = {0xce, STORE_32(d)};
151
+ const unsigned char buf[5] = {0xce, STORE_BE32(d)};
128
152
  msgpack_pack_append_buffer(x, buf, 5);
129
153
  }
130
154
 
131
- inline void msgpack_pack_unsigned_int_64(msgpack_pack_context x, uint64_t d)
155
+ msgpack_pack_inline_func(uint64)(msgpack_pack_user x, uint64_t d)
132
156
  {
133
- // FIXME
134
- const unsigned char buf[9] = {0xcf, STORE_64(d)};
157
+ const unsigned char buf[9] = {0xcf, STORE_BE64(d)};
135
158
  msgpack_pack_append_buffer(x, buf, 9);
136
159
  }
137
160
 
138
- inline void msgpack_pack_signed_int_8(msgpack_pack_context x, int8_t d)
161
+ msgpack_pack_inline_func(int8)(msgpack_pack_user x, int8_t d)
139
162
  {
140
163
  if(d > 0) {
141
164
  msgpack_pack_append_buffer(x, (uint8_t*)&d, 1);
@@ -147,22 +170,21 @@ inline void msgpack_pack_signed_int_8(msgpack_pack_context x, int8_t d)
147
170
  }
148
171
  }
149
172
 
150
- inline void msgpack_pack_signed_int_16(msgpack_pack_context x, int16_t d)
173
+ msgpack_pack_inline_func(int16)(msgpack_pack_user x, int16_t d)
151
174
  {
152
- const unsigned char buf[3] = {0xd1, STORE_16(d)};
175
+ const unsigned char buf[3] = {0xd1, STORE_BE16(d)};
153
176
  msgpack_pack_append_buffer(x, buf, 3);
154
177
  }
155
178
 
156
- inline void msgpack_pack_signed_int_32(msgpack_pack_context x, int32_t d)
179
+ msgpack_pack_inline_func(int32)(msgpack_pack_user x, int32_t d)
157
180
  {
158
- const unsigned char buf[5] = {0xd2, STORE_32(d)};
181
+ const unsigned char buf[5] = {0xd2, STORE_BE32(d)};
159
182
  msgpack_pack_append_buffer(x, buf, 5);
160
183
  }
161
184
 
162
- inline void msgpack_pack_signed_int_64(msgpack_pack_context x, int64_t d)
185
+ msgpack_pack_inline_func(int64)(msgpack_pack_user x, int64_t d)
163
186
  {
164
- // FIXME
165
- const unsigned char buf[9] = {0xd3, STORE_64(d)};
187
+ const unsigned char buf[9] = {0xd3, STORE_BE64(d)};
166
188
  msgpack_pack_append_buffer(x, buf, 9);
167
189
  }
168
190
 
@@ -171,17 +193,17 @@ inline void msgpack_pack_signed_int_64(msgpack_pack_context x, int64_t d)
171
193
  * Float
172
194
  */
173
195
 
174
- inline void msgpack_pack_float(msgpack_pack_context x, float d)
196
+ msgpack_pack_inline_func(float)(msgpack_pack_user x, float d)
175
197
  {
176
198
  uint32_t n = *((uint32_t*)&d); // FIXME
177
- const unsigned char buf[5] = {0xca, STORE_32(n)};
199
+ const unsigned char buf[5] = {0xca, STORE_BE32(n)};
178
200
  msgpack_pack_append_buffer(x, buf, 5);
179
201
  }
180
202
 
181
- inline void msgpack_pack_double(msgpack_pack_context x, double d)
203
+ msgpack_pack_inline_func(double)(msgpack_pack_user x, double d)
182
204
  {
183
205
  uint64_t n = *((uint64_t*)&d); // FIXME
184
- const unsigned char buf[9] = {0xcb, STORE_64(n)};
206
+ const unsigned char buf[9] = {0xcb, STORE_BE64(n)};
185
207
  msgpack_pack_append_buffer(x, buf, 9);
186
208
  }
187
209
 
@@ -190,7 +212,7 @@ inline void msgpack_pack_double(msgpack_pack_context x, double d)
190
212
  * Nil
191
213
  */
192
214
 
193
- inline void msgpack_pack_nil(msgpack_pack_context x)
215
+ msgpack_pack_inline_func(nil)(msgpack_pack_user x)
194
216
  {
195
217
  static const unsigned char d = 0xc0;
196
218
  msgpack_pack_append_buffer(x, &d, 1);
@@ -200,13 +222,14 @@ inline void msgpack_pack_nil(msgpack_pack_context x)
200
222
  /*
201
223
  * Boolean
202
224
  */
203
- inline void msgpack_pack_true(msgpack_pack_context x)
225
+
226
+ msgpack_pack_inline_func(true)(msgpack_pack_user x)
204
227
  {
205
228
  static const unsigned char d = 0xc3;
206
229
  msgpack_pack_append_buffer(x, &d, 1);
207
230
  }
208
231
 
209
- inline void msgpack_pack_false(msgpack_pack_context x)
232
+ msgpack_pack_inline_func(false)(msgpack_pack_user x)
210
233
  {
211
234
  static const unsigned char d = 0xc2;
212
235
  msgpack_pack_append_buffer(x, &d, 1);
@@ -217,18 +240,18 @@ inline void msgpack_pack_false(msgpack_pack_context x)
217
240
  * Array
218
241
  */
219
242
 
220
- inline void msgpack_pack_array(msgpack_pack_context x, unsigned int n)
243
+ msgpack_pack_inline_func(array)(msgpack_pack_user x, unsigned int n)
221
244
  {
222
245
  if(n < 16) {
223
246
  unsigned char d = 0x90 | n;
224
247
  msgpack_pack_append_buffer(x, &d, 1);
225
248
  } else if(n < 65536) {
226
249
  uint16_t d = (uint16_t)n;
227
- unsigned char buf[3] = {0xdc, STORE_16(d)};
250
+ unsigned char buf[3] = {0xdc, STORE_BE16(d)};
228
251
  msgpack_pack_append_buffer(x, buf, 3);
229
252
  } else {
230
253
  uint32_t d = (uint32_t)n;
231
- unsigned char buf[5] = {0xdd, STORE_32(d)};
254
+ unsigned char buf[5] = {0xdd, STORE_BE32(d)};
232
255
  msgpack_pack_append_buffer(x, buf, 5);
233
256
  }
234
257
  }
@@ -238,50 +261,53 @@ inline void msgpack_pack_array(msgpack_pack_context x, unsigned int n)
238
261
  * Map
239
262
  */
240
263
 
241
- inline void msgpack_pack_map(msgpack_pack_context x, unsigned int n)
264
+ msgpack_pack_inline_func(map)(msgpack_pack_user x, unsigned int n)
242
265
  {
243
266
  if(n < 16) {
244
267
  unsigned char d = 0x80 | n;
245
268
  msgpack_pack_append_buffer(x, &d, 1);
246
269
  } else if(n < 65536) {
247
270
  uint16_t d = (uint16_t)n;
248
- unsigned char buf[3] = {0xde, STORE_16(d)};
271
+ unsigned char buf[3] = {0xde, STORE_BE16(d)};
249
272
  msgpack_pack_append_buffer(x, buf, 3);
250
273
  } else {
251
274
  uint32_t d = (uint32_t)n;
252
- unsigned char buf[5] = {0xdf, STORE_32(d)};
275
+ unsigned char buf[5] = {0xdf, STORE_BE32(d)};
253
276
  msgpack_pack_append_buffer(x, buf, 5);
254
277
  }
255
278
  }
256
279
 
257
280
 
258
281
  /*
259
- * String
282
+ * Raw
260
283
  */
261
284
 
262
- inline void msgpack_pack_string(msgpack_pack_context x, const char* b)
263
- {
264
- uint32_t l = strlen(b);
265
- msgpack_pack_append_buffer(x, (const unsigned char*)b, l+1);
266
- }
267
-
268
- inline void msgpack_pack_raw(msgpack_pack_context x, const void* b, size_t l)
285
+ msgpack_pack_inline_func(raw)(msgpack_pack_user x, size_t l)
269
286
  {
270
287
  if(l < 32) {
271
288
  unsigned char d = 0xa0 | l;
272
289
  msgpack_pack_append_buffer(x, &d, 1);
273
290
  } else if(l < 65536) {
274
291
  uint16_t d = (uint16_t)l;
275
- unsigned char buf[3] = {0xda, STORE_16(d)};
292
+ unsigned char buf[3] = {0xda, STORE_BE16(d)};
276
293
  msgpack_pack_append_buffer(x, buf, 3);
277
294
  } else {
278
295
  uint32_t d = (uint32_t)l;
279
- unsigned char buf[5] = {0xdb, STORE_32(d)};
296
+ unsigned char buf[5] = {0xdb, STORE_BE32(d)};
280
297
  msgpack_pack_append_buffer(x, buf, 5);
281
298
  }
282
- msgpack_pack_append_buffer(x, b, l);
283
299
  }
284
300
 
301
+ msgpack_pack_inline_func(raw_body)(msgpack_pack_user x, const void* b, size_t l)
302
+ {
303
+ msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
304
+ }
305
+
306
+ #undef msgpack_pack_inline_func
307
+ #undef msgpack_pack_user
308
+ #undef msgpack_pack_append_buffer
285
309
 
286
- #endif /* msgpack/pack/inline_impl.h */
310
+ #undef STORE_BE16
311
+ #undef STORE_BE32
312
+ #undef STORE_BE64
287
313