msgpack 0.4.7-x86-mingw32 → 0.5.0-x86-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/ChangeLog +47 -0
- data/README.rdoc +102 -0
- data/Rakefile +88 -0
- data/doclib/msgpack.rb +55 -0
- data/doclib/msgpack/buffer.rb +193 -0
- data/doclib/msgpack/core_ext.rb +101 -0
- data/doclib/msgpack/error.rb +14 -0
- data/doclib/msgpack/packer.rb +131 -0
- data/doclib/msgpack/unpacker.rb +130 -0
- data/ext/msgpack/buffer.c +679 -0
- data/ext/msgpack/buffer.h +442 -0
- data/ext/msgpack/buffer_class.c +507 -0
- data/ext/msgpack/buffer_class.h +32 -0
- data/ext/msgpack/compat.h +112 -0
- data/ext/msgpack/core_ext.c +129 -0
- data/ext/{pack.h → msgpack/core_ext.h} +7 -7
- data/ext/msgpack/extconf.rb +17 -0
- data/ext/msgpack/packer.c +137 -0
- data/ext/msgpack/packer.h +319 -0
- data/ext/msgpack/packer_class.c +285 -0
- data/ext/{unpack.h → msgpack/packer_class.h} +11 -7
- data/ext/msgpack/rbinit.c +33 -0
- data/ext/msgpack/rmem.c +110 -0
- data/ext/msgpack/rmem.h +100 -0
- data/ext/msgpack/sysdep.h +115 -0
- data/ext/msgpack/sysdep_endian.h +50 -0
- data/ext/msgpack/sysdep_types.h +46 -0
- data/ext/msgpack/unpacker.c +669 -0
- data/ext/msgpack/unpacker.h +112 -0
- data/ext/msgpack/unpacker_class.c +376 -0
- data/{msgpack/pack_define.h → ext/msgpack/unpacker_class.h} +12 -8
- data/lib/msgpack.rb +10 -1
- data/{ext → lib/msgpack}/version.rb +1 -1
- data/msgpack.gemspec +25 -0
- data/spec/buffer_io_spec.rb +237 -0
- data/spec/buffer_spec.rb +572 -0
- data/{test → spec}/cases.json +0 -0
- data/{test/cases.mpac → spec/cases.msg} +0 -0
- data/{test/cases_compact.mpac → spec/cases_compact.msg} +0 -0
- data/spec/cases_spec.rb +39 -0
- data/spec/format_spec.rb +225 -0
- data/spec/packer_spec.rb +127 -0
- data/spec/random_compat.rb +24 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/unpacker_spec.rb +128 -0
- metadata +157 -39
- data/ext/compat.h +0 -99
- data/ext/extconf.rb +0 -7
- data/ext/pack.c +0 -314
- data/ext/rbinit.c +0 -66
- data/ext/unpack.c +0 -1001
- data/lib/1.8/msgpack.so +0 -0
- data/lib/1.9/msgpack.so +0 -0
- data/msgpack/pack_template.h +0 -771
- data/msgpack/sysdep.h +0 -195
- data/msgpack/unpack_define.h +0 -93
- data/msgpack/unpack_template.h +0 -413
- data/test/test_cases.rb +0 -46
- data/test/test_encoding.rb +0 -68
- data/test/test_helper.rb +0 -10
- data/test/test_pack_unpack.rb +0 -308
data/msgpack/sysdep.h
DELETED
@@ -1,195 +0,0 @@
|
|
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
|
-
#include <stdlib.h>
|
22
|
-
#include <stddef.h>
|
23
|
-
#if defined(_MSC_VER) && _MSC_VER < 1600
|
24
|
-
typedef __int8 int8_t;
|
25
|
-
typedef unsigned __int8 uint8_t;
|
26
|
-
typedef __int16 int16_t;
|
27
|
-
typedef unsigned __int16 uint16_t;
|
28
|
-
typedef __int32 int32_t;
|
29
|
-
typedef unsigned __int32 uint32_t;
|
30
|
-
typedef __int64 int64_t;
|
31
|
-
typedef unsigned __int64 uint64_t;
|
32
|
-
#elif defined(_MSC_VER) // && _MSC_VER >= 1600
|
33
|
-
#include <stdint.h>
|
34
|
-
#else
|
35
|
-
#include <stdint.h>
|
36
|
-
#include <stdbool.h>
|
37
|
-
#endif
|
38
|
-
|
39
|
-
#ifdef _WIN32
|
40
|
-
#define _msgpack_atomic_counter_header <windows.h>
|
41
|
-
typedef long _msgpack_atomic_counter_t;
|
42
|
-
#define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr)
|
43
|
-
#define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr)
|
44
|
-
#elif defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41)
|
45
|
-
#define _msgpack_atomic_counter_header "gcc_atomic.h"
|
46
|
-
#else
|
47
|
-
typedef unsigned int _msgpack_atomic_counter_t;
|
48
|
-
#define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1)
|
49
|
-
#define _msgpack_sync_incr_and_fetch(ptr) __sync_add_and_fetch(ptr, 1)
|
50
|
-
#endif
|
51
|
-
|
52
|
-
#ifdef _WIN32
|
53
|
-
|
54
|
-
#ifdef __cplusplus
|
55
|
-
/* numeric_limits<T>::min,max */
|
56
|
-
#ifdef max
|
57
|
-
#undef max
|
58
|
-
#endif
|
59
|
-
#ifdef min
|
60
|
-
#undef min
|
61
|
-
#endif
|
62
|
-
#endif
|
63
|
-
|
64
|
-
#else
|
65
|
-
#include <arpa/inet.h> /* __BYTE_ORDER */
|
66
|
-
#endif
|
67
|
-
|
68
|
-
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
|
69
|
-
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
70
|
-
#define __LITTLE_ENDIAN__
|
71
|
-
#elif __BYTE_ORDER == __BIG_ENDIAN
|
72
|
-
#define __BIG_ENDIAN__
|
73
|
-
#elif _WIN32
|
74
|
-
#define __LITTLE_ENDIAN__
|
75
|
-
#endif
|
76
|
-
#endif
|
77
|
-
|
78
|
-
|
79
|
-
#ifdef __LITTLE_ENDIAN__
|
80
|
-
|
81
|
-
#ifdef _WIN32
|
82
|
-
# if defined(ntohs)
|
83
|
-
# define _msgpack_be16(x) ntohs(x)
|
84
|
-
# elif defined(_byteswap_ushort) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
85
|
-
# define _msgpack_be16(x) ((uint16_t)_byteswap_ushort((unsigned short)x))
|
86
|
-
# else
|
87
|
-
# define _msgpack_be16(x) ( \
|
88
|
-
((((uint16_t)x) << 8) ) | \
|
89
|
-
((((uint16_t)x) >> 8) ) )
|
90
|
-
# endif
|
91
|
-
#else
|
92
|
-
# define _msgpack_be16(x) ntohs(x)
|
93
|
-
#endif
|
94
|
-
|
95
|
-
#ifdef _WIN32
|
96
|
-
# if defined(ntohl)
|
97
|
-
# define _msgpack_be32(x) ntohl(x)
|
98
|
-
# elif defined(_byteswap_ulong) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
99
|
-
# define _msgpack_be32(x) ((uint32_t)_byteswap_ulong((unsigned long)x))
|
100
|
-
# else
|
101
|
-
# define _msgpack_be32(x) \
|
102
|
-
( ((((uint32_t)x) << 24) ) | \
|
103
|
-
((((uint32_t)x) << 8) & 0x00ff0000U ) | \
|
104
|
-
((((uint32_t)x) >> 8) & 0x0000ff00U ) | \
|
105
|
-
((((uint32_t)x) >> 24) ) )
|
106
|
-
# endif
|
107
|
-
#else
|
108
|
-
# define _msgpack_be32(x) ntohl(x)
|
109
|
-
#endif
|
110
|
-
|
111
|
-
#if defined(_byteswap_uint64) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
112
|
-
# define _msgpack_be64(x) (_byteswap_uint64(x))
|
113
|
-
#elif defined(bswap_64)
|
114
|
-
# define _msgpack_be64(x) bswap_64(x)
|
115
|
-
#elif defined(__DARWIN_OSSwapInt64)
|
116
|
-
# define _msgpack_be64(x) __DARWIN_OSSwapInt64(x)
|
117
|
-
#else
|
118
|
-
#define _msgpack_be64(x) \
|
119
|
-
( ((((uint64_t)x) << 56) ) | \
|
120
|
-
((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \
|
121
|
-
((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \
|
122
|
-
((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \
|
123
|
-
((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \
|
124
|
-
((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \
|
125
|
-
((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \
|
126
|
-
((((uint64_t)x) >> 56) ) )
|
127
|
-
#endif
|
128
|
-
|
129
|
-
#define _msgpack_load16(cast, from) ((cast)( \
|
130
|
-
(((uint16_t)((uint8_t*)(from))[0]) << 8) | \
|
131
|
-
(((uint16_t)((uint8_t*)(from))[1]) ) ))
|
132
|
-
|
133
|
-
#define _msgpack_load32(cast, from) ((cast)( \
|
134
|
-
(((uint32_t)((uint8_t*)(from))[0]) << 24) | \
|
135
|
-
(((uint32_t)((uint8_t*)(from))[1]) << 16) | \
|
136
|
-
(((uint32_t)((uint8_t*)(from))[2]) << 8) | \
|
137
|
-
(((uint32_t)((uint8_t*)(from))[3]) ) ))
|
138
|
-
|
139
|
-
#define _msgpack_load64(cast, from) ((cast)( \
|
140
|
-
(((uint64_t)((uint8_t*)(from))[0]) << 56) | \
|
141
|
-
(((uint64_t)((uint8_t*)(from))[1]) << 48) | \
|
142
|
-
(((uint64_t)((uint8_t*)(from))[2]) << 40) | \
|
143
|
-
(((uint64_t)((uint8_t*)(from))[3]) << 32) | \
|
144
|
-
(((uint64_t)((uint8_t*)(from))[4]) << 24) | \
|
145
|
-
(((uint64_t)((uint8_t*)(from))[5]) << 16) | \
|
146
|
-
(((uint64_t)((uint8_t*)(from))[6]) << 8) | \
|
147
|
-
(((uint64_t)((uint8_t*)(from))[7]) ) ))
|
148
|
-
|
149
|
-
#else
|
150
|
-
|
151
|
-
#define _msgpack_be16(x) (x)
|
152
|
-
#define _msgpack_be32(x) (x)
|
153
|
-
#define _msgpack_be64(x) (x)
|
154
|
-
|
155
|
-
#define _msgpack_load16(cast, from) ((cast)( \
|
156
|
-
(((uint16_t)((uint8_t*)from)[0]) << 8) | \
|
157
|
-
(((uint16_t)((uint8_t*)from)[1]) ) ))
|
158
|
-
|
159
|
-
#define _msgpack_load32(cast, from) ((cast)( \
|
160
|
-
(((uint32_t)((uint8_t*)from)[0]) << 24) | \
|
161
|
-
(((uint32_t)((uint8_t*)from)[1]) << 16) | \
|
162
|
-
(((uint32_t)((uint8_t*)from)[2]) << 8) | \
|
163
|
-
(((uint32_t)((uint8_t*)from)[3]) ) ))
|
164
|
-
|
165
|
-
#define _msgpack_load64(cast, from) ((cast)( \
|
166
|
-
(((uint64_t)((uint8_t*)from)[0]) << 56) | \
|
167
|
-
(((uint64_t)((uint8_t*)from)[1]) << 48) | \
|
168
|
-
(((uint64_t)((uint8_t*)from)[2]) << 40) | \
|
169
|
-
(((uint64_t)((uint8_t*)from)[3]) << 32) | \
|
170
|
-
(((uint64_t)((uint8_t*)from)[4]) << 24) | \
|
171
|
-
(((uint64_t)((uint8_t*)from)[5]) << 16) | \
|
172
|
-
(((uint64_t)((uint8_t*)from)[6]) << 8) | \
|
173
|
-
(((uint64_t)((uint8_t*)from)[7]) ) ))
|
174
|
-
#endif
|
175
|
-
|
176
|
-
|
177
|
-
#define _msgpack_store16(to, num) \
|
178
|
-
do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0)
|
179
|
-
#define _msgpack_store32(to, num) \
|
180
|
-
do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0)
|
181
|
-
#define _msgpack_store64(to, num) \
|
182
|
-
do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0)
|
183
|
-
|
184
|
-
/*
|
185
|
-
#define _msgpack_load16(cast, from) \
|
186
|
-
({ cast val; memcpy(&val, (char*)from, 2); _msgpack_be16(val); })
|
187
|
-
#define _msgpack_load32(cast, from) \
|
188
|
-
({ cast val; memcpy(&val, (char*)from, 4); _msgpack_be32(val); })
|
189
|
-
#define _msgpack_load64(cast, from) \
|
190
|
-
({ cast val; memcpy(&val, (char*)from, 8); _msgpack_be64(val); })
|
191
|
-
*/
|
192
|
-
|
193
|
-
|
194
|
-
#endif /* msgpack/sysdep.h */
|
195
|
-
|
data/msgpack/unpack_define.h
DELETED
@@ -1,93 +0,0 @@
|
|
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 <stdlib.h>
|
23
|
-
#include <string.h>
|
24
|
-
#include <assert.h>
|
25
|
-
#include <stdio.h>
|
26
|
-
|
27
|
-
#ifdef __cplusplus
|
28
|
-
extern "C" {
|
29
|
-
#endif
|
30
|
-
|
31
|
-
|
32
|
-
#ifndef MSGPACK_EMBED_STACK_SIZE
|
33
|
-
#define MSGPACK_EMBED_STACK_SIZE 32
|
34
|
-
#endif
|
35
|
-
|
36
|
-
|
37
|
-
typedef enum {
|
38
|
-
CS_HEADER = 0x00, // nil
|
39
|
-
|
40
|
-
//CS_ = 0x01,
|
41
|
-
//CS_ = 0x02, // false
|
42
|
-
//CS_ = 0x03, // true
|
43
|
-
|
44
|
-
//CS_ = 0x04,
|
45
|
-
//CS_ = 0x05,
|
46
|
-
//CS_ = 0x06,
|
47
|
-
//CS_ = 0x07,
|
48
|
-
|
49
|
-
//CS_ = 0x08,
|
50
|
-
//CS_ = 0x09,
|
51
|
-
CS_FLOAT = 0x0a,
|
52
|
-
CS_DOUBLE = 0x0b,
|
53
|
-
CS_UINT_8 = 0x0c,
|
54
|
-
CS_UINT_16 = 0x0d,
|
55
|
-
CS_UINT_32 = 0x0e,
|
56
|
-
CS_UINT_64 = 0x0f,
|
57
|
-
CS_INT_8 = 0x10,
|
58
|
-
CS_INT_16 = 0x11,
|
59
|
-
CS_INT_32 = 0x12,
|
60
|
-
CS_INT_64 = 0x13,
|
61
|
-
|
62
|
-
//CS_ = 0x14,
|
63
|
-
//CS_ = 0x15,
|
64
|
-
//CS_BIG_INT_16 = 0x16,
|
65
|
-
//CS_BIG_INT_32 = 0x17,
|
66
|
-
//CS_BIG_FLOAT_16 = 0x18,
|
67
|
-
//CS_BIG_FLOAT_32 = 0x19,
|
68
|
-
CS_RAW_16 = 0x1a,
|
69
|
-
CS_RAW_32 = 0x1b,
|
70
|
-
CS_ARRAY_16 = 0x1c,
|
71
|
-
CS_ARRAY_32 = 0x1d,
|
72
|
-
CS_MAP_16 = 0x1e,
|
73
|
-
CS_MAP_32 = 0x1f,
|
74
|
-
|
75
|
-
//ACS_BIG_INT_VALUE,
|
76
|
-
//ACS_BIG_FLOAT_VALUE,
|
77
|
-
ACS_RAW_VALUE,
|
78
|
-
} msgpack_unpack_state;
|
79
|
-
|
80
|
-
|
81
|
-
typedef enum {
|
82
|
-
CT_ARRAY_ITEM,
|
83
|
-
CT_MAP_KEY,
|
84
|
-
CT_MAP_VALUE,
|
85
|
-
} msgpack_container_type;
|
86
|
-
|
87
|
-
|
88
|
-
#ifdef __cplusplus
|
89
|
-
}
|
90
|
-
#endif
|
91
|
-
|
92
|
-
#endif /* msgpack/unpack_define.h */
|
93
|
-
|
data/msgpack/unpack_template.h
DELETED
@@ -1,413 +0,0 @@
|
|
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
|
-
/*
|
62
|
-
msgpack_unpack_struct(_stack)* stack;
|
63
|
-
unsigned int stack_size;
|
64
|
-
msgpack_unpack_struct(_stack) embed_stack[MSGPACK_EMBED_STACK_SIZE];
|
65
|
-
*/
|
66
|
-
msgpack_unpack_struct(_stack) stack[MSGPACK_EMBED_STACK_SIZE];
|
67
|
-
};
|
68
|
-
|
69
|
-
|
70
|
-
msgpack_unpack_func(void, _init)(msgpack_unpack_struct(_context)* ctx)
|
71
|
-
{
|
72
|
-
ctx->cs = CS_HEADER;
|
73
|
-
ctx->trail = 0;
|
74
|
-
ctx->top = 0;
|
75
|
-
/*
|
76
|
-
ctx->stack = ctx->embed_stack;
|
77
|
-
ctx->stack_size = MSGPACK_EMBED_STACK_SIZE;
|
78
|
-
*/
|
79
|
-
ctx->stack[0].obj = msgpack_unpack_callback(_root)(&ctx->user);
|
80
|
-
}
|
81
|
-
|
82
|
-
/*
|
83
|
-
msgpack_unpack_func(void, _destroy)(msgpack_unpack_struct(_context)* ctx)
|
84
|
-
{
|
85
|
-
if(ctx->stack_size != MSGPACK_EMBED_STACK_SIZE) {
|
86
|
-
free(ctx->stack);
|
87
|
-
}
|
88
|
-
}
|
89
|
-
*/
|
90
|
-
|
91
|
-
msgpack_unpack_func(msgpack_unpack_object, _data)(msgpack_unpack_struct(_context)* ctx)
|
92
|
-
{
|
93
|
-
return (ctx)->stack[0].obj;
|
94
|
-
}
|
95
|
-
|
96
|
-
|
97
|
-
msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const char* data, size_t len, size_t* off)
|
98
|
-
{
|
99
|
-
assert(len >= *off);
|
100
|
-
|
101
|
-
const unsigned char* p = (unsigned char*)data + *off;
|
102
|
-
const unsigned char* const pe = (unsigned char*)data + len;
|
103
|
-
const void* n = NULL;
|
104
|
-
|
105
|
-
unsigned int trail = ctx->trail;
|
106
|
-
unsigned int cs = ctx->cs;
|
107
|
-
unsigned int top = ctx->top;
|
108
|
-
msgpack_unpack_struct(_stack)* stack = ctx->stack;
|
109
|
-
/*
|
110
|
-
unsigned int stack_size = ctx->stack_size;
|
111
|
-
*/
|
112
|
-
msgpack_unpack_user* user = &ctx->user;
|
113
|
-
|
114
|
-
msgpack_unpack_object obj;
|
115
|
-
msgpack_unpack_struct(_stack)* c = NULL;
|
116
|
-
|
117
|
-
int ret;
|
118
|
-
|
119
|
-
#define push_simple_value(func) \
|
120
|
-
if(msgpack_unpack_callback(func)(user, &obj) < 0) { goto _failed; } \
|
121
|
-
goto _push
|
122
|
-
#define push_fixed_value(func, arg) \
|
123
|
-
if(msgpack_unpack_callback(func)(user, arg, &obj) < 0) { goto _failed; } \
|
124
|
-
goto _push
|
125
|
-
#define push_variable_value(func, base, pos, len) \
|
126
|
-
if(msgpack_unpack_callback(func)(user, \
|
127
|
-
(const char*)base, (const char*)pos, len, &obj) < 0) { goto _failed; } \
|
128
|
-
goto _push
|
129
|
-
|
130
|
-
#define again_fixed_trail(_cs, trail_len) \
|
131
|
-
trail = trail_len; \
|
132
|
-
cs = _cs; \
|
133
|
-
goto _fixed_trail_again
|
134
|
-
#define again_fixed_trail_if_zero(_cs, trail_len, ifzero) \
|
135
|
-
trail = trail_len; \
|
136
|
-
if(trail == 0) { goto ifzero; } \
|
137
|
-
cs = _cs; \
|
138
|
-
goto _fixed_trail_again
|
139
|
-
|
140
|
-
#define start_container(func, count_, ct_) \
|
141
|
-
if(top >= MSGPACK_EMBED_STACK_SIZE) { goto _failed; } /* FIXME */ \
|
142
|
-
if(msgpack_unpack_callback(func)(user, count_, &stack[top].obj) < 0) { goto _failed; } \
|
143
|
-
if((count_) == 0) { obj = stack[top].obj; goto _push; } \
|
144
|
-
stack[top].ct = ct_; \
|
145
|
-
stack[top].count = count_; \
|
146
|
-
++top; \
|
147
|
-
/*printf("container %d count %d stack %d\n",stack[top].obj,count_,top);*/ \
|
148
|
-
/*printf("stack push %d\n", top);*/ \
|
149
|
-
/* FIXME \
|
150
|
-
if(top >= stack_size) { \
|
151
|
-
if(stack_size == MSGPACK_EMBED_STACK_SIZE) { \
|
152
|
-
size_t csize = sizeof(msgpack_unpack_struct(_stack)) * MSGPACK_EMBED_STACK_SIZE; \
|
153
|
-
size_t nsize = csize * 2; \
|
154
|
-
msgpack_unpack_struct(_stack)* tmp = (msgpack_unpack_struct(_stack)*)malloc(nsize); \
|
155
|
-
if(tmp == NULL) { goto _failed; } \
|
156
|
-
memcpy(tmp, ctx->stack, csize); \
|
157
|
-
ctx->stack = stack = tmp; \
|
158
|
-
ctx->stack_size = stack_size = MSGPACK_EMBED_STACK_SIZE * 2; \
|
159
|
-
} else { \
|
160
|
-
size_t nsize = sizeof(msgpack_unpack_struct(_stack)) * ctx->stack_size * 2; \
|
161
|
-
msgpack_unpack_struct(_stack)* tmp = (msgpack_unpack_struct(_stack)*)realloc(ctx->stack, nsize); \
|
162
|
-
if(tmp == NULL) { goto _failed; } \
|
163
|
-
ctx->stack = stack = tmp; \
|
164
|
-
ctx->stack_size = stack_size = stack_size * 2; \
|
165
|
-
} \
|
166
|
-
} \
|
167
|
-
*/ \
|
168
|
-
goto _header_again
|
169
|
-
|
170
|
-
#define NEXT_CS(p) \
|
171
|
-
((unsigned int)*p & 0x1f)
|
172
|
-
|
173
|
-
#ifdef USE_CASE_RANGE
|
174
|
-
#define SWITCH_RANGE_BEGIN switch(*p) {
|
175
|
-
#define SWITCH_RANGE(FROM, TO) case FROM ... TO:
|
176
|
-
#define SWITCH_RANGE_DEFAULT default:
|
177
|
-
#define SWITCH_RANGE_END }
|
178
|
-
#else
|
179
|
-
#define SWITCH_RANGE_BEGIN { if(0) {
|
180
|
-
#define SWITCH_RANGE(FROM, TO) } else if(FROM <= *p && *p <= TO) {
|
181
|
-
#define SWITCH_RANGE_DEFAULT } else {
|
182
|
-
#define SWITCH_RANGE_END } }
|
183
|
-
#endif
|
184
|
-
|
185
|
-
if(p == pe) { goto _out; }
|
186
|
-
do {
|
187
|
-
switch(cs) {
|
188
|
-
case CS_HEADER:
|
189
|
-
SWITCH_RANGE_BEGIN
|
190
|
-
SWITCH_RANGE(0x00, 0x7f) // Positive Fixnum
|
191
|
-
push_fixed_value(_uint8, *(uint8_t*)p);
|
192
|
-
SWITCH_RANGE(0xe0, 0xff) // Negative Fixnum
|
193
|
-
push_fixed_value(_int8, *(int8_t*)p);
|
194
|
-
SWITCH_RANGE(0xc0, 0xdf) // Variable
|
195
|
-
switch(*p) {
|
196
|
-
case 0xc0: // nil
|
197
|
-
push_simple_value(_nil);
|
198
|
-
//case 0xc1: // string
|
199
|
-
// again_terminal_trail(NEXT_CS(p), p+1);
|
200
|
-
case 0xc2: // false
|
201
|
-
push_simple_value(_false);
|
202
|
-
case 0xc3: // true
|
203
|
-
push_simple_value(_true);
|
204
|
-
//case 0xc4:
|
205
|
-
//case 0xc5:
|
206
|
-
//case 0xc6:
|
207
|
-
//case 0xc7:
|
208
|
-
//case 0xc8:
|
209
|
-
//case 0xc9:
|
210
|
-
case 0xca: // float
|
211
|
-
case 0xcb: // double
|
212
|
-
case 0xcc: // unsigned int 8
|
213
|
-
case 0xcd: // unsigned int 16
|
214
|
-
case 0xce: // unsigned int 32
|
215
|
-
case 0xcf: // unsigned int 64
|
216
|
-
case 0xd0: // signed int 8
|
217
|
-
case 0xd1: // signed int 16
|
218
|
-
case 0xd2: // signed int 32
|
219
|
-
case 0xd3: // signed int 64
|
220
|
-
again_fixed_trail(NEXT_CS(p), 1 << (((unsigned int)*p) & 0x03));
|
221
|
-
//case 0xd4:
|
222
|
-
//case 0xd5:
|
223
|
-
//case 0xd6: // big integer 16
|
224
|
-
//case 0xd7: // big integer 32
|
225
|
-
//case 0xd8: // big float 16
|
226
|
-
//case 0xd9: // big float 32
|
227
|
-
case 0xda: // raw 16
|
228
|
-
case 0xdb: // raw 32
|
229
|
-
case 0xdc: // array 16
|
230
|
-
case 0xdd: // array 32
|
231
|
-
case 0xde: // map 16
|
232
|
-
case 0xdf: // map 32
|
233
|
-
again_fixed_trail(NEXT_CS(p), 2 << (((unsigned int)*p) & 0x01));
|
234
|
-
default:
|
235
|
-
goto _failed;
|
236
|
-
}
|
237
|
-
SWITCH_RANGE(0xa0, 0xbf) // FixRaw
|
238
|
-
again_fixed_trail_if_zero(ACS_RAW_VALUE, ((unsigned int)*p & 0x1f), _raw_zero);
|
239
|
-
SWITCH_RANGE(0x90, 0x9f) // FixArray
|
240
|
-
start_container(_array, ((unsigned int)*p) & 0x0f, CT_ARRAY_ITEM);
|
241
|
-
SWITCH_RANGE(0x80, 0x8f) // FixMap
|
242
|
-
start_container(_map, ((unsigned int)*p) & 0x0f, CT_MAP_KEY);
|
243
|
-
|
244
|
-
SWITCH_RANGE_DEFAULT
|
245
|
-
goto _failed;
|
246
|
-
SWITCH_RANGE_END
|
247
|
-
// end CS_HEADER
|
248
|
-
|
249
|
-
|
250
|
-
_fixed_trail_again:
|
251
|
-
++p;
|
252
|
-
|
253
|
-
default:
|
254
|
-
if((size_t)(pe - p) < trail) { goto _out; }
|
255
|
-
n = p; p += trail - 1;
|
256
|
-
switch(cs) {
|
257
|
-
//case CS_
|
258
|
-
//case CS_
|
259
|
-
case CS_FLOAT: {
|
260
|
-
union { uint32_t i; float f; } mem;
|
261
|
-
mem.i = _msgpack_load32(uint32_t,n);
|
262
|
-
push_fixed_value(_float, mem.f); }
|
263
|
-
case CS_DOUBLE: {
|
264
|
-
union { uint64_t i; double f; } mem;
|
265
|
-
mem.i = _msgpack_load64(uint64_t,n);
|
266
|
-
#if defined(__arm__) && !(__ARM_EABI__) // arm-oabi
|
267
|
-
// https://github.com/msgpack/msgpack-perl/pull/1
|
268
|
-
mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
|
269
|
-
#endif
|
270
|
-
push_fixed_value(_double, mem.f); }
|
271
|
-
case CS_UINT_8:
|
272
|
-
push_fixed_value(_uint8, *(uint8_t*)n);
|
273
|
-
case CS_UINT_16:
|
274
|
-
push_fixed_value(_uint16, _msgpack_load16(uint16_t,n));
|
275
|
-
case CS_UINT_32:
|
276
|
-
push_fixed_value(_uint32, _msgpack_load32(uint32_t,n));
|
277
|
-
case CS_UINT_64:
|
278
|
-
push_fixed_value(_uint64, _msgpack_load64(uint64_t,n));
|
279
|
-
|
280
|
-
case CS_INT_8:
|
281
|
-
push_fixed_value(_int8, *(int8_t*)n);
|
282
|
-
case CS_INT_16:
|
283
|
-
push_fixed_value(_int16, _msgpack_load16(int16_t,n));
|
284
|
-
case CS_INT_32:
|
285
|
-
push_fixed_value(_int32, _msgpack_load32(int32_t,n));
|
286
|
-
case CS_INT_64:
|
287
|
-
push_fixed_value(_int64, _msgpack_load64(int64_t,n));
|
288
|
-
|
289
|
-
//case CS_
|
290
|
-
//case CS_
|
291
|
-
//case CS_BIG_INT_16:
|
292
|
-
// again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, _msgpack_load16(uint16_t,n), _big_int_zero);
|
293
|
-
//case CS_BIG_INT_32:
|
294
|
-
// again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, _msgpack_load32(uint32_t,n), _big_int_zero);
|
295
|
-
//case ACS_BIG_INT_VALUE:
|
296
|
-
//_big_int_zero:
|
297
|
-
// // FIXME
|
298
|
-
// push_variable_value(_big_int, data, n, trail);
|
299
|
-
|
300
|
-
//case CS_BIG_FLOAT_16:
|
301
|
-
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, _msgpack_load16(uint16_t,n), _big_float_zero);
|
302
|
-
//case CS_BIG_FLOAT_32:
|
303
|
-
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, _msgpack_load32(uint32_t,n), _big_float_zero);
|
304
|
-
//case ACS_BIG_FLOAT_VALUE:
|
305
|
-
//_big_float_zero:
|
306
|
-
// // FIXME
|
307
|
-
// push_variable_value(_big_float, data, n, trail);
|
308
|
-
|
309
|
-
case CS_RAW_16:
|
310
|
-
again_fixed_trail_if_zero(ACS_RAW_VALUE, _msgpack_load16(uint16_t,n), _raw_zero);
|
311
|
-
case CS_RAW_32:
|
312
|
-
again_fixed_trail_if_zero(ACS_RAW_VALUE, _msgpack_load32(uint32_t,n), _raw_zero);
|
313
|
-
case ACS_RAW_VALUE:
|
314
|
-
_raw_zero:
|
315
|
-
push_variable_value(_raw, data, n, trail);
|
316
|
-
|
317
|
-
case CS_ARRAY_16:
|
318
|
-
start_container(_array, _msgpack_load16(uint16_t,n), CT_ARRAY_ITEM);
|
319
|
-
case CS_ARRAY_32:
|
320
|
-
/* FIXME security guard */
|
321
|
-
start_container(_array, _msgpack_load32(uint32_t,n), CT_ARRAY_ITEM);
|
322
|
-
|
323
|
-
case CS_MAP_16:
|
324
|
-
start_container(_map, _msgpack_load16(uint16_t,n), CT_MAP_KEY);
|
325
|
-
case CS_MAP_32:
|
326
|
-
/* FIXME security guard */
|
327
|
-
start_container(_map, _msgpack_load32(uint32_t,n), CT_MAP_KEY);
|
328
|
-
|
329
|
-
default:
|
330
|
-
goto _failed;
|
331
|
-
}
|
332
|
-
}
|
333
|
-
|
334
|
-
_push:
|
335
|
-
if(top == 0) { goto _finish; }
|
336
|
-
c = &stack[top-1];
|
337
|
-
switch(c->ct) {
|
338
|
-
case CT_ARRAY_ITEM:
|
339
|
-
if(msgpack_unpack_callback(_array_item)(user, &c->obj, obj) < 0) { goto _failed; }
|
340
|
-
if(--c->count == 0) {
|
341
|
-
obj = c->obj;
|
342
|
-
--top;
|
343
|
-
/*printf("stack pop %d\n", top);*/
|
344
|
-
goto _push;
|
345
|
-
}
|
346
|
-
goto _header_again;
|
347
|
-
case CT_MAP_KEY:
|
348
|
-
c->map_key = obj;
|
349
|
-
c->ct = CT_MAP_VALUE;
|
350
|
-
goto _header_again;
|
351
|
-
case CT_MAP_VALUE:
|
352
|
-
if(msgpack_unpack_callback(_map_item)(user, &c->obj, c->map_key, obj) < 0) { goto _failed; }
|
353
|
-
if(--c->count == 0) {
|
354
|
-
obj = c->obj;
|
355
|
-
--top;
|
356
|
-
/*printf("stack pop %d\n", top);*/
|
357
|
-
goto _push;
|
358
|
-
}
|
359
|
-
c->ct = CT_MAP_KEY;
|
360
|
-
goto _header_again;
|
361
|
-
|
362
|
-
default:
|
363
|
-
goto _failed;
|
364
|
-
}
|
365
|
-
|
366
|
-
_header_again:
|
367
|
-
cs = CS_HEADER;
|
368
|
-
++p;
|
369
|
-
} while(p != pe);
|
370
|
-
goto _out;
|
371
|
-
|
372
|
-
|
373
|
-
_finish:
|
374
|
-
stack[0].obj = obj;
|
375
|
-
++p;
|
376
|
-
ret = 1;
|
377
|
-
/*printf("-- finish --\n"); */
|
378
|
-
goto _end;
|
379
|
-
|
380
|
-
_failed:
|
381
|
-
/*printf("** FAILED **\n"); */
|
382
|
-
ret = -1;
|
383
|
-
goto _end;
|
384
|
-
|
385
|
-
_out:
|
386
|
-
ret = 0;
|
387
|
-
goto _end;
|
388
|
-
|
389
|
-
_end:
|
390
|
-
ctx->cs = cs;
|
391
|
-
ctx->trail = trail;
|
392
|
-
ctx->top = top;
|
393
|
-
*off = p - (const unsigned char*)data;
|
394
|
-
|
395
|
-
return ret;
|
396
|
-
}
|
397
|
-
|
398
|
-
|
399
|
-
#undef msgpack_unpack_func
|
400
|
-
#undef msgpack_unpack_callback
|
401
|
-
#undef msgpack_unpack_struct
|
402
|
-
#undef msgpack_unpack_object
|
403
|
-
#undef msgpack_unpack_user
|
404
|
-
|
405
|
-
#undef push_simple_value
|
406
|
-
#undef push_fixed_value
|
407
|
-
#undef push_variable_value
|
408
|
-
#undef again_fixed_trail
|
409
|
-
#undef again_fixed_trail_if_zero
|
410
|
-
#undef start_container
|
411
|
-
|
412
|
-
#undef NEXT_CS
|
413
|
-
|