msgpack 0.3.2-mswin32 → 0.3.3-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +1 -0
- data/ChangeLog +0 -0
- data/README +29 -0
- data/ext/unpack.c +120 -7
- data/msgpack/pack_define.h +26 -0
- data/msgpack/pack_template.h +686 -0
- data/msgpack/sysdep.h +118 -0
- data/msgpack/unpack_define.h +92 -0
- data/msgpack/unpack_template.h +369 -0
- data/test/msgpack_test.rb +225 -0
- data/test/test_helper.rb +3 -0
- metadata +21 -14
- data/ext/Makefile +0 -156
- data/ext/msgpack.so +0 -0
- data/ext/pack.o +0 -0
- data/ext/rbinit.o +0 -0
- data/ext/unpack.o +0 -0
data/msgpack/sysdep.h
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack system dependencies
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
5
|
+
*
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
* you may not use this file except in compliance with the License.
|
8
|
+
* You may obtain a copy of the License at
|
9
|
+
*
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
*
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
* See the License for the specific language governing permissions and
|
16
|
+
* limitations under the License.
|
17
|
+
*/
|
18
|
+
#ifndef MSGPACK_SYSDEP_H__
|
19
|
+
#define MSGPACK_SYSDEP_H__
|
20
|
+
|
21
|
+
|
22
|
+
#ifdef _MSC_VER
|
23
|
+
typedef __int8 int8_t;
|
24
|
+
typedef unsigned __int8 uint8_t;
|
25
|
+
typedef __int16 int16_t;
|
26
|
+
typedef unsigned __int16 uint16_t;
|
27
|
+
typedef __int32 int32_t;
|
28
|
+
typedef unsigned __int32 uint32_t;
|
29
|
+
typedef __int64 int64_t;
|
30
|
+
typedef unsigned __int64 uint64_t;
|
31
|
+
#else
|
32
|
+
#include <stddef.h>
|
33
|
+
#include <stdint.h>
|
34
|
+
#include <stdbool.h>
|
35
|
+
#endif
|
36
|
+
|
37
|
+
|
38
|
+
#ifdef _WIN32
|
39
|
+
typedef long _msgpack_atomic_counter_t;
|
40
|
+
#define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr)
|
41
|
+
#define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr)
|
42
|
+
#else
|
43
|
+
typedef unsigned int _msgpack_atomic_counter_t;
|
44
|
+
#define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1)
|
45
|
+
#define _msgpack_sync_incr_and_fetch(ptr) __sync_add_and_fetch(ptr, 1)
|
46
|
+
#endif
|
47
|
+
|
48
|
+
|
49
|
+
#ifdef _WIN32
|
50
|
+
#include <winsock2.h>
|
51
|
+
|
52
|
+
#ifdef __cplusplus
|
53
|
+
/* numeric_limits<T>::min,max */
|
54
|
+
#ifdef max
|
55
|
+
#undef max
|
56
|
+
#endif
|
57
|
+
#ifdef min
|
58
|
+
#undef min
|
59
|
+
#endif
|
60
|
+
#endif
|
61
|
+
|
62
|
+
#else
|
63
|
+
#include <arpa/inet.h> /* __BYTE_ORDER */
|
64
|
+
#endif
|
65
|
+
|
66
|
+
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
|
67
|
+
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
68
|
+
#define __LITTLE_ENDIAN__
|
69
|
+
#elif __BYTE_ORDER == __BIG_ENDIAN
|
70
|
+
#define __BIG_ENDIAN__
|
71
|
+
#endif
|
72
|
+
#endif
|
73
|
+
|
74
|
+
#ifdef __LITTLE_ENDIAN__
|
75
|
+
|
76
|
+
#define _msgpack_be16(x) ntohs(x)
|
77
|
+
#define _msgpack_be32(x) ntohl(x)
|
78
|
+
|
79
|
+
#if defined(_byteswap_uint64)
|
80
|
+
# define _msgpack_be64(x) (_byteswap_uint64(x))
|
81
|
+
#elif defined(bswap_64)
|
82
|
+
# define _msgpack_be64(x) bswap_64(x)
|
83
|
+
#elif defined(__DARWIN_OSSwapInt64)
|
84
|
+
# define _msgpack_be64(x) __DARWIN_OSSwapInt64(x)
|
85
|
+
#else
|
86
|
+
#define _msgpack_be64(x) \
|
87
|
+
( ((((uint64_t)x) << 56) & 0xff00000000000000ULL ) | \
|
88
|
+
((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \
|
89
|
+
((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \
|
90
|
+
((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \
|
91
|
+
((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \
|
92
|
+
((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \
|
93
|
+
((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \
|
94
|
+
((((uint64_t)x) >> 56) & 0x00000000000000ffULL ) )
|
95
|
+
#endif
|
96
|
+
|
97
|
+
#else
|
98
|
+
#define _msgpack_be16(x) (x)
|
99
|
+
#define _msgpack_be32(x) (x)
|
100
|
+
#define _msgpack_be64(x) (x)
|
101
|
+
#endif
|
102
|
+
|
103
|
+
|
104
|
+
#define _msgpack_store16(to, num) \
|
105
|
+
do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0);
|
106
|
+
#define _msgpack_store32(to, num) \
|
107
|
+
do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0);
|
108
|
+
#define _msgpack_store64(to, num) \
|
109
|
+
do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0);
|
110
|
+
|
111
|
+
|
112
|
+
#define _msgpack_load16(cast, from) ((cast)_msgpack_be16(*(uint16_t*)from))
|
113
|
+
#define _msgpack_load32(cast, from) ((cast)_msgpack_be32(*(uint32_t*)from))
|
114
|
+
#define _msgpack_load64(cast, from) ((cast)_msgpack_be64(*(uint64_t*)from))
|
115
|
+
|
116
|
+
|
117
|
+
#endif /* msgpack/sysdep.h */
|
118
|
+
|
@@ -0,0 +1,92 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack unpacking routine template
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
5
|
+
*
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
* you may not use this file except in compliance with the License.
|
8
|
+
* You may obtain a copy of the License at
|
9
|
+
*
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
*
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
* See the License for the specific language governing permissions and
|
16
|
+
* limitations under the License.
|
17
|
+
*/
|
18
|
+
#ifndef MSGPACK_UNPACK_DEFINE_H__
|
19
|
+
#define MSGPACK_UNPACK_DEFINE_H__
|
20
|
+
|
21
|
+
#include "msgpack/sysdep.h"
|
22
|
+
#include <string.h>
|
23
|
+
#include <assert.h>
|
24
|
+
#include <stdio.h>
|
25
|
+
|
26
|
+
#ifdef __cplusplus
|
27
|
+
extern "C" {
|
28
|
+
#endif
|
29
|
+
|
30
|
+
|
31
|
+
#ifndef MSGPACK_MAX_STACK_SIZE
|
32
|
+
#define MSGPACK_MAX_STACK_SIZE 16
|
33
|
+
#endif
|
34
|
+
|
35
|
+
|
36
|
+
typedef enum {
|
37
|
+
CS_HEADER = 0x00, // nil
|
38
|
+
|
39
|
+
//CS_ = 0x01,
|
40
|
+
//CS_ = 0x02, // false
|
41
|
+
//CS_ = 0x03, // true
|
42
|
+
|
43
|
+
//CS_ = 0x04,
|
44
|
+
//CS_ = 0x05,
|
45
|
+
//CS_ = 0x06,
|
46
|
+
//CS_ = 0x07,
|
47
|
+
|
48
|
+
//CS_ = 0x08,
|
49
|
+
//CS_ = 0x09,
|
50
|
+
CS_FLOAT = 0x0a,
|
51
|
+
CS_DOUBLE = 0x0b,
|
52
|
+
CS_UINT_8 = 0x0c,
|
53
|
+
CS_UINT_16 = 0x0d,
|
54
|
+
CS_UINT_32 = 0x0e,
|
55
|
+
CS_UINT_64 = 0x0f,
|
56
|
+
CS_INT_8 = 0x10,
|
57
|
+
CS_INT_16 = 0x11,
|
58
|
+
CS_INT_32 = 0x12,
|
59
|
+
CS_INT_64 = 0x13,
|
60
|
+
|
61
|
+
//CS_ = 0x14,
|
62
|
+
//CS_ = 0x15,
|
63
|
+
//CS_BIG_INT_16 = 0x16,
|
64
|
+
//CS_BIG_INT_32 = 0x17,
|
65
|
+
//CS_BIG_FLOAT_16 = 0x18,
|
66
|
+
//CS_BIG_FLOAT_32 = 0x19,
|
67
|
+
CS_RAW_16 = 0x1a,
|
68
|
+
CS_RAW_32 = 0x1b,
|
69
|
+
CS_ARRAY_16 = 0x1c,
|
70
|
+
CS_ARRAY_32 = 0x1d,
|
71
|
+
CS_MAP_16 = 0x1e,
|
72
|
+
CS_MAP_32 = 0x1f,
|
73
|
+
|
74
|
+
//ACS_BIG_INT_VALUE,
|
75
|
+
//ACS_BIG_FLOAT_VALUE,
|
76
|
+
ACS_RAW_VALUE,
|
77
|
+
} msgpack_unpack_state;
|
78
|
+
|
79
|
+
|
80
|
+
typedef enum {
|
81
|
+
CT_ARRAY_ITEM,
|
82
|
+
CT_MAP_KEY,
|
83
|
+
CT_MAP_VALUE,
|
84
|
+
} msgpack_container_type;
|
85
|
+
|
86
|
+
|
87
|
+
#ifdef __cplusplus
|
88
|
+
}
|
89
|
+
#endif
|
90
|
+
|
91
|
+
#endif /* msgpack/unpack_define.h */
|
92
|
+
|
@@ -0,0 +1,369 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack unpacking routine template
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
5
|
+
*
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
* you may not use this file except in compliance with the License.
|
8
|
+
* You may obtain a copy of the License at
|
9
|
+
*
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
*
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
* See the License for the specific language governing permissions and
|
16
|
+
* limitations under the License.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef msgpack_unpack_func
|
20
|
+
#error msgpack_unpack_func template is not defined
|
21
|
+
#endif
|
22
|
+
|
23
|
+
#ifndef msgpack_unpack_callback
|
24
|
+
#error msgpack_unpack_callback template is not defined
|
25
|
+
#endif
|
26
|
+
|
27
|
+
#ifndef msgpack_unpack_struct
|
28
|
+
#error msgpack_unpack_struct template is not defined
|
29
|
+
#endif
|
30
|
+
|
31
|
+
#ifndef msgpack_unpack_struct_decl
|
32
|
+
#define msgpack_unpack_struct_decl(name) msgpack_unpack_struct(name)
|
33
|
+
#endif
|
34
|
+
|
35
|
+
#ifndef msgpack_unpack_object
|
36
|
+
#error msgpack_unpack_object type is not defined
|
37
|
+
#endif
|
38
|
+
|
39
|
+
#ifndef msgpack_unpack_user
|
40
|
+
#error msgpack_unpack_user type is not defined
|
41
|
+
#endif
|
42
|
+
|
43
|
+
#ifndef USE_CASE_RANGE
|
44
|
+
#if !defined(_MSC_VER)
|
45
|
+
#define USE_CASE_RANGE
|
46
|
+
#endif
|
47
|
+
#endif
|
48
|
+
|
49
|
+
msgpack_unpack_struct_decl(_stack) {
|
50
|
+
msgpack_unpack_object obj;
|
51
|
+
size_t count;
|
52
|
+
unsigned int ct;
|
53
|
+
msgpack_unpack_object map_key;
|
54
|
+
};
|
55
|
+
|
56
|
+
msgpack_unpack_struct_decl(_context) {
|
57
|
+
msgpack_unpack_user user;
|
58
|
+
unsigned int cs;
|
59
|
+
unsigned int trail;
|
60
|
+
unsigned int top;
|
61
|
+
msgpack_unpack_struct(_stack) stack[MSGPACK_MAX_STACK_SIZE];
|
62
|
+
};
|
63
|
+
|
64
|
+
|
65
|
+
msgpack_unpack_func(void, _init)(msgpack_unpack_struct(_context)* ctx)
|
66
|
+
{
|
67
|
+
ctx->cs = CS_HEADER;
|
68
|
+
ctx->trail = 0;
|
69
|
+
ctx->top = 0;
|
70
|
+
ctx->stack[0].obj = msgpack_unpack_callback(_root)(&ctx->user);
|
71
|
+
}
|
72
|
+
|
73
|
+
msgpack_unpack_func(msgpack_unpack_object, _data)(msgpack_unpack_struct(_context)* ctx)
|
74
|
+
{
|
75
|
+
return (ctx)->stack[0].obj;
|
76
|
+
}
|
77
|
+
|
78
|
+
|
79
|
+
msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const char* data, size_t len, size_t* off)
|
80
|
+
{
|
81
|
+
assert(len >= *off);
|
82
|
+
|
83
|
+
const unsigned char* p = (unsigned char*)data + *off;
|
84
|
+
const unsigned char* const pe = (unsigned char*)data + len;
|
85
|
+
const void* n = NULL;
|
86
|
+
|
87
|
+
unsigned int trail = ctx->trail;
|
88
|
+
unsigned int cs = ctx->cs;
|
89
|
+
unsigned int top = ctx->top;
|
90
|
+
msgpack_unpack_struct(_stack)* stack = ctx->stack;
|
91
|
+
msgpack_unpack_user* user = &ctx->user;
|
92
|
+
|
93
|
+
msgpack_unpack_object obj;
|
94
|
+
msgpack_unpack_struct(_stack)* c = NULL;
|
95
|
+
|
96
|
+
int ret;
|
97
|
+
|
98
|
+
#define push_simple_value(func) \
|
99
|
+
if(msgpack_unpack_callback(func)(user, &obj) < 0) { goto _failed; } \
|
100
|
+
goto _push
|
101
|
+
#define push_fixed_value(func, arg) \
|
102
|
+
if(msgpack_unpack_callback(func)(user, arg, &obj) < 0) { goto _failed; } \
|
103
|
+
goto _push
|
104
|
+
#define push_variable_value(func, base, pos, len) \
|
105
|
+
if(msgpack_unpack_callback(func)(user, \
|
106
|
+
(const char*)base, (const char*)pos, len, &obj) < 0) { goto _failed; } \
|
107
|
+
goto _push
|
108
|
+
|
109
|
+
#define again_fixed_trail(_cs, trail_len) \
|
110
|
+
trail = trail_len; \
|
111
|
+
cs = _cs; \
|
112
|
+
goto _fixed_trail_again
|
113
|
+
#define again_fixed_trail_if_zero(_cs, trail_len, ifzero) \
|
114
|
+
trail = trail_len; \
|
115
|
+
if(trail == 0) { goto ifzero; } \
|
116
|
+
cs = _cs; \
|
117
|
+
goto _fixed_trail_again
|
118
|
+
|
119
|
+
#define start_container(func, count_, ct_) \
|
120
|
+
if(msgpack_unpack_callback(func)(user, count_, &stack[top].obj) < 0) { goto _failed; } \
|
121
|
+
if((count_) == 0) { obj = stack[top].obj; goto _push; } \
|
122
|
+
if(top >= MSGPACK_MAX_STACK_SIZE) { goto _failed; } \
|
123
|
+
stack[top].ct = ct_; \
|
124
|
+
stack[top].count = count_; \
|
125
|
+
/*printf("container %d count %d stack %d\n",stack[top].obj,count_,top);*/ \
|
126
|
+
/*printf("stack push %d\n", top);*/ \
|
127
|
+
++top; \
|
128
|
+
goto _header_again
|
129
|
+
|
130
|
+
#define NEXT_CS(p) \
|
131
|
+
((unsigned int)*p & 0x1f)
|
132
|
+
|
133
|
+
#ifdef USE_CASE_RANGE
|
134
|
+
#define SWITCH_RANGE_BEGIN switch(*p) {
|
135
|
+
#define SWITCH_RANGE(FROM, TO) case FROM ... TO:
|
136
|
+
#define SWITCH_RANGE_DEFAULT default:
|
137
|
+
#define SWITCH_RANGE_END }
|
138
|
+
#else
|
139
|
+
#define SWITCH_RANGE_BEGIN { if(0) {
|
140
|
+
#define SWITCH_RANGE(FROM, TO) } else if(FROM <= *p && *p <= TO) {
|
141
|
+
#define SWITCH_RANGE_DEFAULT } else {
|
142
|
+
#define SWITCH_RANGE_END } }
|
143
|
+
#endif
|
144
|
+
|
145
|
+
if(p == pe) { goto _out; }
|
146
|
+
do {
|
147
|
+
switch(cs) {
|
148
|
+
case CS_HEADER:
|
149
|
+
SWITCH_RANGE_BEGIN
|
150
|
+
SWITCH_RANGE(0x00, 0x7f) // Positive Fixnum
|
151
|
+
push_fixed_value(_uint8, *(uint8_t*)p);
|
152
|
+
SWITCH_RANGE(0xe0, 0xff) // Negative Fixnum
|
153
|
+
push_fixed_value(_int8, *(int8_t*)p);
|
154
|
+
SWITCH_RANGE(0xc0, 0xdf) // Variable
|
155
|
+
switch(*p) {
|
156
|
+
case 0xc0: // nil
|
157
|
+
push_simple_value(_nil);
|
158
|
+
//case 0xc1: // string
|
159
|
+
// again_terminal_trail(NEXT_CS(p), p+1);
|
160
|
+
case 0xc2: // false
|
161
|
+
push_simple_value(_false);
|
162
|
+
case 0xc3: // true
|
163
|
+
push_simple_value(_true);
|
164
|
+
//case 0xc4:
|
165
|
+
//case 0xc5:
|
166
|
+
//case 0xc6:
|
167
|
+
//case 0xc7:
|
168
|
+
//case 0xc8:
|
169
|
+
//case 0xc9:
|
170
|
+
case 0xca: // float
|
171
|
+
case 0xcb: // double
|
172
|
+
case 0xcc: // unsigned int 8
|
173
|
+
case 0xcd: // unsigned int 16
|
174
|
+
case 0xce: // unsigned int 32
|
175
|
+
case 0xcf: // unsigned int 64
|
176
|
+
case 0xd0: // signed int 8
|
177
|
+
case 0xd1: // signed int 16
|
178
|
+
case 0xd2: // signed int 32
|
179
|
+
case 0xd3: // signed int 64
|
180
|
+
again_fixed_trail(NEXT_CS(p), 1 << (((unsigned int)*p) & 0x03));
|
181
|
+
//case 0xd4:
|
182
|
+
//case 0xd5:
|
183
|
+
//case 0xd6: // big integer 16
|
184
|
+
//case 0xd7: // big integer 32
|
185
|
+
//case 0xd8: // big float 16
|
186
|
+
//case 0xd9: // big float 32
|
187
|
+
case 0xda: // raw 16
|
188
|
+
case 0xdb: // raw 32
|
189
|
+
case 0xdc: // array 16
|
190
|
+
case 0xdd: // array 32
|
191
|
+
case 0xde: // map 16
|
192
|
+
case 0xdf: // map 32
|
193
|
+
again_fixed_trail(NEXT_CS(p), 2 << (((unsigned int)*p) & 0x01));
|
194
|
+
default:
|
195
|
+
goto _failed;
|
196
|
+
}
|
197
|
+
SWITCH_RANGE(0xa0, 0xbf) // FixRaw
|
198
|
+
again_fixed_trail_if_zero(ACS_RAW_VALUE, ((unsigned int)*p & 0x1f), _raw_zero);
|
199
|
+
SWITCH_RANGE(0x90, 0x9f) // FixArray
|
200
|
+
start_container(_array, ((unsigned int)*p) & 0x0f, CT_ARRAY_ITEM);
|
201
|
+
SWITCH_RANGE(0x80, 0x8f) // FixMap
|
202
|
+
start_container(_map, ((unsigned int)*p) & 0x0f, CT_MAP_KEY);
|
203
|
+
|
204
|
+
SWITCH_RANGE_DEFAULT
|
205
|
+
goto _failed;
|
206
|
+
SWITCH_RANGE_END
|
207
|
+
// end CS_HEADER
|
208
|
+
|
209
|
+
|
210
|
+
_fixed_trail_again:
|
211
|
+
++p;
|
212
|
+
|
213
|
+
default:
|
214
|
+
if((size_t)(pe - p) < trail) { goto _out; }
|
215
|
+
n = p; p += trail - 1;
|
216
|
+
switch(cs) {
|
217
|
+
//case CS_
|
218
|
+
//case CS_
|
219
|
+
case CS_FLOAT: {
|
220
|
+
union { uint32_t i; float f; } mem;
|
221
|
+
mem.i = _msgpack_load32(uint32_t,n);
|
222
|
+
push_fixed_value(_float, mem.f); }
|
223
|
+
case CS_DOUBLE: {
|
224
|
+
union { uint64_t i; double f; } mem;
|
225
|
+
mem.i = _msgpack_load64(uint64_t,n);
|
226
|
+
push_fixed_value(_double, mem.f); }
|
227
|
+
case CS_UINT_8:
|
228
|
+
push_fixed_value(_uint8, *(uint8_t*)n);
|
229
|
+
case CS_UINT_16:
|
230
|
+
push_fixed_value(_uint16, _msgpack_load16(uint16_t,n));
|
231
|
+
case CS_UINT_32:
|
232
|
+
push_fixed_value(_uint32, _msgpack_load32(uint32_t,n));
|
233
|
+
case CS_UINT_64:
|
234
|
+
push_fixed_value(_uint64, _msgpack_load64(uint64_t,n));
|
235
|
+
|
236
|
+
case CS_INT_8:
|
237
|
+
push_fixed_value(_int8, *(int8_t*)n);
|
238
|
+
case CS_INT_16:
|
239
|
+
push_fixed_value(_int16, _msgpack_load16(int16_t,n));
|
240
|
+
case CS_INT_32:
|
241
|
+
push_fixed_value(_int32, _msgpack_load32(int32_t,n));
|
242
|
+
case CS_INT_64:
|
243
|
+
push_fixed_value(_int64, _msgpack_load64(int64_t,n));
|
244
|
+
|
245
|
+
//case CS_
|
246
|
+
//case CS_
|
247
|
+
//case CS_BIG_INT_16:
|
248
|
+
// again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, _msgpack_load16(uint16_t,n), _big_int_zero);
|
249
|
+
//case CS_BIG_INT_32:
|
250
|
+
// again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, _msgpack_load32(uint32_t,n), _big_int_zero);
|
251
|
+
//case ACS_BIG_INT_VALUE:
|
252
|
+
//_big_int_zero:
|
253
|
+
// // FIXME
|
254
|
+
// push_variable_value(_big_int, data, n, trail);
|
255
|
+
|
256
|
+
//case CS_BIG_FLOAT_16:
|
257
|
+
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, _msgpack_load16(uint16_t,n), _big_float_zero);
|
258
|
+
//case CS_BIG_FLOAT_32:
|
259
|
+
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, _msgpack_load32(uint32_t,n), _big_float_zero);
|
260
|
+
//case ACS_BIG_FLOAT_VALUE:
|
261
|
+
//_big_float_zero:
|
262
|
+
// // FIXME
|
263
|
+
// push_variable_value(_big_float, data, n, trail);
|
264
|
+
|
265
|
+
case CS_RAW_16:
|
266
|
+
again_fixed_trail_if_zero(ACS_RAW_VALUE, _msgpack_load16(uint16_t,n), _raw_zero);
|
267
|
+
case CS_RAW_32:
|
268
|
+
again_fixed_trail_if_zero(ACS_RAW_VALUE, _msgpack_load32(uint32_t,n), _raw_zero);
|
269
|
+
case ACS_RAW_VALUE:
|
270
|
+
_raw_zero:
|
271
|
+
push_variable_value(_raw, data, n, trail);
|
272
|
+
|
273
|
+
case CS_ARRAY_16:
|
274
|
+
start_container(_array, _msgpack_load16(uint16_t,n), CT_ARRAY_ITEM);
|
275
|
+
case CS_ARRAY_32:
|
276
|
+
/* FIXME security guard */
|
277
|
+
start_container(_array, _msgpack_load32(uint32_t,n), CT_ARRAY_ITEM);
|
278
|
+
|
279
|
+
case CS_MAP_16:
|
280
|
+
start_container(_map, _msgpack_load16(uint16_t,n), CT_MAP_KEY);
|
281
|
+
case CS_MAP_32:
|
282
|
+
/* FIXME security guard */
|
283
|
+
start_container(_map, _msgpack_load32(uint32_t,n), CT_MAP_KEY);
|
284
|
+
|
285
|
+
default:
|
286
|
+
goto _failed;
|
287
|
+
}
|
288
|
+
}
|
289
|
+
|
290
|
+
_push:
|
291
|
+
if(top == 0) { goto _finish; }
|
292
|
+
c = &stack[top-1];
|
293
|
+
switch(c->ct) {
|
294
|
+
case CT_ARRAY_ITEM:
|
295
|
+
if(msgpack_unpack_callback(_array_item)(user, &c->obj, obj) < 0) { goto _failed; }
|
296
|
+
if(--c->count == 0) {
|
297
|
+
obj = c->obj;
|
298
|
+
--top;
|
299
|
+
/*printf("stack pop %d\n", top);*/
|
300
|
+
goto _push;
|
301
|
+
}
|
302
|
+
goto _header_again;
|
303
|
+
case CT_MAP_KEY:
|
304
|
+
c->map_key = obj;
|
305
|
+
c->ct = CT_MAP_VALUE;
|
306
|
+
goto _header_again;
|
307
|
+
case CT_MAP_VALUE:
|
308
|
+
if(msgpack_unpack_callback(_map_item)(user, &c->obj, c->map_key, obj) < 0) { goto _failed; }
|
309
|
+
if(--c->count == 0) {
|
310
|
+
obj = c->obj;
|
311
|
+
--top;
|
312
|
+
/*printf("stack pop %d\n", top);*/
|
313
|
+
goto _push;
|
314
|
+
}
|
315
|
+
c->ct = CT_MAP_KEY;
|
316
|
+
goto _header_again;
|
317
|
+
|
318
|
+
default:
|
319
|
+
goto _failed;
|
320
|
+
}
|
321
|
+
|
322
|
+
_header_again:
|
323
|
+
cs = CS_HEADER;
|
324
|
+
++p;
|
325
|
+
} while(p != pe);
|
326
|
+
goto _out;
|
327
|
+
|
328
|
+
|
329
|
+
_finish:
|
330
|
+
stack[0].obj = obj;
|
331
|
+
++p;
|
332
|
+
ret = 1;
|
333
|
+
/*printf("-- finish --\n"); */
|
334
|
+
goto _end;
|
335
|
+
|
336
|
+
_failed:
|
337
|
+
/*printf("** FAILED **\n"); */
|
338
|
+
ret = -1;
|
339
|
+
goto _end;
|
340
|
+
|
341
|
+
_out:
|
342
|
+
ret = 0;
|
343
|
+
goto _end;
|
344
|
+
|
345
|
+
_end:
|
346
|
+
ctx->cs = cs;
|
347
|
+
ctx->trail = trail;
|
348
|
+
ctx->top = top;
|
349
|
+
*off = p - (const unsigned char*)data;
|
350
|
+
|
351
|
+
return ret;
|
352
|
+
}
|
353
|
+
|
354
|
+
|
355
|
+
#undef msgpack_unpack_func
|
356
|
+
#undef msgpack_unpack_callback
|
357
|
+
#undef msgpack_unpack_struct
|
358
|
+
#undef msgpack_unpack_object
|
359
|
+
#undef msgpack_unpack_user
|
360
|
+
|
361
|
+
#undef push_simple_value
|
362
|
+
#undef push_fixed_value
|
363
|
+
#undef push_variable_value
|
364
|
+
#undef again_fixed_trail
|
365
|
+
#undef again_fixed_trail_if_zero
|
366
|
+
#undef start_container
|
367
|
+
|
368
|
+
#undef NEXT_CS
|
369
|
+
|