sq_detailed_metrics 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/extconf.rb +26 -0
- data/include/half.hpp +4575 -0
- data/include/msgpack.h +24 -0
- data/include/msgpack/fbuffer.h +42 -0
- data/include/msgpack/gcc_atomic.h +25 -0
- data/include/msgpack/object.h +118 -0
- data/include/msgpack/pack.h +174 -0
- data/include/msgpack/pack_define.h +18 -0
- data/include/msgpack/pack_template.h +952 -0
- data/include/msgpack/sbuffer.h +115 -0
- data/include/msgpack/sysdep.h +221 -0
- data/include/msgpack/timestamp.h +58 -0
- data/include/msgpack/unpack.h +281 -0
- data/include/msgpack/unpack_define.h +89 -0
- data/include/msgpack/unpack_template.h +471 -0
- data/include/msgpack/util.h +15 -0
- data/include/msgpack/version.h +38 -0
- data/include/msgpack/version_master.h +3 -0
- data/include/msgpack/vrefbuffer.h +144 -0
- data/include/msgpack/zbuffer.h +205 -0
- data/include/msgpack/zone.h +163 -0
- data/include/rapidjson/allocators.h +271 -0
- data/include/rapidjson/document.h +2575 -0
- data/include/rapidjson/encodedstream.h +299 -0
- data/include/rapidjson/encodings.h +716 -0
- data/include/rapidjson/error/en.h +74 -0
- data/include/rapidjson/error/error.h +155 -0
- data/include/rapidjson/filereadstream.h +99 -0
- data/include/rapidjson/filewritestream.h +104 -0
- data/include/rapidjson/fwd.h +151 -0
- data/include/rapidjson/internal/biginteger.h +290 -0
- data/include/rapidjson/internal/diyfp.h +258 -0
- data/include/rapidjson/internal/dtoa.h +245 -0
- data/include/rapidjson/internal/ieee754.h +78 -0
- data/include/rapidjson/internal/itoa.h +304 -0
- data/include/rapidjson/internal/meta.h +181 -0
- data/include/rapidjson/internal/pow10.h +55 -0
- data/include/rapidjson/internal/regex.h +701 -0
- data/include/rapidjson/internal/stack.h +230 -0
- data/include/rapidjson/internal/strfunc.h +55 -0
- data/include/rapidjson/internal/strtod.h +269 -0
- data/include/rapidjson/internal/swap.h +46 -0
- data/include/rapidjson/istreamwrapper.h +115 -0
- data/include/rapidjson/memorybuffer.h +70 -0
- data/include/rapidjson/memorystream.h +71 -0
- data/include/rapidjson/msinttypes/inttypes.h +316 -0
- data/include/rapidjson/msinttypes/stdint.h +300 -0
- data/include/rapidjson/ostreamwrapper.h +81 -0
- data/include/rapidjson/pointer.h +1358 -0
- data/include/rapidjson/prettywriter.h +255 -0
- data/include/rapidjson/rapidjson.h +615 -0
- data/include/rapidjson/reader.h +1879 -0
- data/include/rapidjson/schema.h +2006 -0
- data/include/rapidjson/stream.h +179 -0
- data/include/rapidjson/stringbuffer.h +117 -0
- data/include/rapidjson/writer.h +610 -0
- data/include/xxhash.h +328 -0
- data/json_conv.cpp +284 -0
- data/json_conv.hpp +17 -0
- data/metrics.cpp +239 -0
- data/metrics.hpp +84 -0
- data/msgpack/objectc.c +482 -0
- data/msgpack/unpack.c +703 -0
- data/msgpack/version.c +22 -0
- data/msgpack/vrefbuffer.c +250 -0
- data/msgpack/zone.c +222 -0
- data/sq_detailed_metrics.cpp +248 -0
- metadata +199 -0
@@ -0,0 +1,115 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack for C simple buffer implementation
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
5
|
+
*
|
6
|
+
* Distributed under the Boost Software License, Version 1.0.
|
7
|
+
* (See accompanying file LICENSE_1_0.txt or copy at
|
8
|
+
* http://www.boost.org/LICENSE_1_0.txt)
|
9
|
+
*/
|
10
|
+
#ifndef MSGPACK_SBUFFER_H
|
11
|
+
#define MSGPACK_SBUFFER_H
|
12
|
+
|
13
|
+
#include <stdlib.h>
|
14
|
+
#include <string.h>
|
15
|
+
#include <assert.h>
|
16
|
+
|
17
|
+
#ifdef __cplusplus
|
18
|
+
extern "C" {
|
19
|
+
#endif
|
20
|
+
|
21
|
+
|
22
|
+
/**
|
23
|
+
* @defgroup msgpack_sbuffer Simple buffer
|
24
|
+
* @ingroup msgpack_buffer
|
25
|
+
* @{
|
26
|
+
*/
|
27
|
+
|
28
|
+
typedef struct msgpack_sbuffer {
|
29
|
+
size_t size;
|
30
|
+
char* data;
|
31
|
+
size_t alloc;
|
32
|
+
} msgpack_sbuffer;
|
33
|
+
|
34
|
+
static inline void msgpack_sbuffer_init(msgpack_sbuffer* sbuf)
|
35
|
+
{
|
36
|
+
memset(sbuf, 0, sizeof(msgpack_sbuffer));
|
37
|
+
}
|
38
|
+
|
39
|
+
static inline void msgpack_sbuffer_destroy(msgpack_sbuffer* sbuf)
|
40
|
+
{
|
41
|
+
free(sbuf->data);
|
42
|
+
}
|
43
|
+
|
44
|
+
static inline msgpack_sbuffer* msgpack_sbuffer_new(void)
|
45
|
+
{
|
46
|
+
return (msgpack_sbuffer*)calloc(1, sizeof(msgpack_sbuffer));
|
47
|
+
}
|
48
|
+
|
49
|
+
static inline void msgpack_sbuffer_free(msgpack_sbuffer* sbuf)
|
50
|
+
{
|
51
|
+
if(sbuf == NULL) { return; }
|
52
|
+
msgpack_sbuffer_destroy(sbuf);
|
53
|
+
free(sbuf);
|
54
|
+
}
|
55
|
+
|
56
|
+
#ifndef MSGPACK_SBUFFER_INIT_SIZE
|
57
|
+
#define MSGPACK_SBUFFER_INIT_SIZE 8192
|
58
|
+
#endif
|
59
|
+
|
60
|
+
static inline int msgpack_sbuffer_write(void* data, const char* buf, size_t len)
|
61
|
+
{
|
62
|
+
msgpack_sbuffer* sbuf = (msgpack_sbuffer*)data;
|
63
|
+
|
64
|
+
assert(buf || len == 0);
|
65
|
+
if(!buf) return 0;
|
66
|
+
|
67
|
+
if(sbuf->alloc - sbuf->size < len) {
|
68
|
+
void* tmp;
|
69
|
+
size_t nsize = (sbuf->alloc) ?
|
70
|
+
sbuf->alloc * 2 : MSGPACK_SBUFFER_INIT_SIZE;
|
71
|
+
|
72
|
+
while(nsize < sbuf->size + len) {
|
73
|
+
size_t tmp_nsize = nsize * 2;
|
74
|
+
if (tmp_nsize <= nsize) {
|
75
|
+
nsize = sbuf->size + len;
|
76
|
+
break;
|
77
|
+
}
|
78
|
+
nsize = tmp_nsize;
|
79
|
+
}
|
80
|
+
|
81
|
+
tmp = realloc(sbuf->data, nsize);
|
82
|
+
if(!tmp) { return -1; }
|
83
|
+
|
84
|
+
sbuf->data = (char*)tmp;
|
85
|
+
sbuf->alloc = nsize;
|
86
|
+
}
|
87
|
+
|
88
|
+
memcpy(sbuf->data + sbuf->size, buf, len);
|
89
|
+
sbuf->size += len;
|
90
|
+
|
91
|
+
return 0;
|
92
|
+
}
|
93
|
+
|
94
|
+
static inline char* msgpack_sbuffer_release(msgpack_sbuffer* sbuf)
|
95
|
+
{
|
96
|
+
char* tmp = sbuf->data;
|
97
|
+
sbuf->size = 0;
|
98
|
+
sbuf->data = NULL;
|
99
|
+
sbuf->alloc = 0;
|
100
|
+
return tmp;
|
101
|
+
}
|
102
|
+
|
103
|
+
static inline void msgpack_sbuffer_clear(msgpack_sbuffer* sbuf)
|
104
|
+
{
|
105
|
+
sbuf->size = 0;
|
106
|
+
}
|
107
|
+
|
108
|
+
/** @} */
|
109
|
+
|
110
|
+
|
111
|
+
#ifdef __cplusplus
|
112
|
+
}
|
113
|
+
#endif
|
114
|
+
|
115
|
+
#endif /* msgpack/sbuffer.h */
|
@@ -0,0 +1,221 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack system dependencies
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
5
|
+
*
|
6
|
+
* Distributed under the Boost Software License, Version 1.0.
|
7
|
+
* (See accompanying file LICENSE_1_0.txt or copy at
|
8
|
+
* http://www.boost.org/LICENSE_1_0.txt)
|
9
|
+
*/
|
10
|
+
#ifndef MSGPACK_SYSDEP_H
|
11
|
+
#define MSGPACK_SYSDEP_H
|
12
|
+
|
13
|
+
#include <stdlib.h>
|
14
|
+
#include <stddef.h>
|
15
|
+
|
16
|
+
#ifndef MSGPACK_ENDIAN_BIG_BYTE
|
17
|
+
#define MSGPACK_ENDIAN_BIG_BYTE 0
|
18
|
+
#endif
|
19
|
+
#ifndef MSGPACK_ENDIAN_LITTLE_BYTE
|
20
|
+
#define MSGPACK_ENDIAN_LITTLE_BYTE 1
|
21
|
+
#endif
|
22
|
+
|
23
|
+
#if defined(_MSC_VER) && _MSC_VER <= 1800
|
24
|
+
# define snprintf(buf, len, format,...) _snprintf_s(buf, len, _TRUNCATE, format, __VA_ARGS__)
|
25
|
+
#endif
|
26
|
+
|
27
|
+
#if defined(_MSC_VER) && _MSC_VER < 1600
|
28
|
+
typedef signed __int8 int8_t;
|
29
|
+
typedef unsigned __int8 uint8_t;
|
30
|
+
typedef signed __int16 int16_t;
|
31
|
+
typedef unsigned __int16 uint16_t;
|
32
|
+
typedef signed __int32 int32_t;
|
33
|
+
typedef unsigned __int32 uint32_t;
|
34
|
+
typedef signed __int64 int64_t;
|
35
|
+
typedef unsigned __int64 uint64_t;
|
36
|
+
#elif defined(_MSC_VER) // && _MSC_VER >= 1600
|
37
|
+
# include <stdint.h>
|
38
|
+
#else
|
39
|
+
# include <stdint.h>
|
40
|
+
# include <stdbool.h>
|
41
|
+
#endif
|
42
|
+
|
43
|
+
#if !defined(MSGPACK_DLLEXPORT)
|
44
|
+
#if defined(_MSC_VER)
|
45
|
+
# define MSGPACK_DLLEXPORT __declspec(dllexport)
|
46
|
+
#else /* _MSC_VER */
|
47
|
+
# define MSGPACK_DLLEXPORT
|
48
|
+
#endif /* _MSC_VER */
|
49
|
+
#endif
|
50
|
+
|
51
|
+
#ifdef _WIN32
|
52
|
+
# if defined(_KERNEL_MODE)
|
53
|
+
# define _msgpack_atomic_counter_header <ntddk.h>
|
54
|
+
# else
|
55
|
+
# define _msgpack_atomic_counter_header <windows.h>
|
56
|
+
# if !defined(WIN32_LEAN_AND_MEAN)
|
57
|
+
# define WIN32_LEAN_AND_MEAN
|
58
|
+
# endif /* WIN32_LEAN_AND_MEAN */
|
59
|
+
# endif
|
60
|
+
typedef long _msgpack_atomic_counter_t;
|
61
|
+
#if defined(_AMD64_) || defined(_M_X64) || defined(_M_ARM64)
|
62
|
+
# define _msgpack_sync_decr_and_fetch(ptr) _InterlockedDecrement(ptr)
|
63
|
+
# define _msgpack_sync_incr_and_fetch(ptr) _InterlockedIncrement(ptr)
|
64
|
+
#else
|
65
|
+
# define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr)
|
66
|
+
# define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr)
|
67
|
+
#endif
|
68
|
+
#elif defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41)
|
69
|
+
|
70
|
+
# if defined(__cplusplus)
|
71
|
+
# define _msgpack_atomic_counter_header "msgpack/gcc_atomic.hpp"
|
72
|
+
# else
|
73
|
+
# define _msgpack_atomic_counter_header "msgpack/gcc_atomic.h"
|
74
|
+
# endif
|
75
|
+
|
76
|
+
#else
|
77
|
+
typedef unsigned int _msgpack_atomic_counter_t;
|
78
|
+
# define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1)
|
79
|
+
# define _msgpack_sync_incr_and_fetch(ptr) __sync_add_and_fetch(ptr, 1)
|
80
|
+
#endif
|
81
|
+
|
82
|
+
#ifdef _WIN32
|
83
|
+
|
84
|
+
# ifdef __cplusplus
|
85
|
+
/* numeric_limits<T>::min,max */
|
86
|
+
# ifdef max
|
87
|
+
# undef max
|
88
|
+
# endif
|
89
|
+
# ifdef min
|
90
|
+
# undef min
|
91
|
+
# endif
|
92
|
+
# endif
|
93
|
+
|
94
|
+
#elif defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
|
95
|
+
|
96
|
+
#include <arpa/inet.h> /* __BYTE_ORDER */
|
97
|
+
# if defined(linux)
|
98
|
+
# include <byteswap.h>
|
99
|
+
# endif
|
100
|
+
|
101
|
+
#endif
|
102
|
+
|
103
|
+
#if !defined(MSGPACK_ENDIAN_LITTLE_BYTE) && !defined(MSGPACK_ENDIAN_BIG_BYTE)
|
104
|
+
#include <msgpack/predef/other/endian.h>
|
105
|
+
#endif // !defined(MSGPACK_ENDIAN_LITTLE_BYTE) && !defined(MSGPACK_ENDIAN_BIG_BYTE)
|
106
|
+
|
107
|
+
#if MSGPACK_ENDIAN_LITTLE_BYTE
|
108
|
+
|
109
|
+
# if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
|
110
|
+
# define _msgpack_be16(x) ntohs((uint16_t)x)
|
111
|
+
# else
|
112
|
+
# if defined(ntohs)
|
113
|
+
# define _msgpack_be16(x) ntohs(x)
|
114
|
+
# elif defined(_byteswap_ushort) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
115
|
+
# define _msgpack_be16(x) ((uint16_t)_byteswap_ushort((unsigned short)x))
|
116
|
+
# else
|
117
|
+
# define _msgpack_be16(x) ( \
|
118
|
+
((((uint16_t)x) << 8) ) | \
|
119
|
+
((((uint16_t)x) >> 8) ) )
|
120
|
+
# endif
|
121
|
+
# endif
|
122
|
+
|
123
|
+
# if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
|
124
|
+
# define _msgpack_be32(x) ntohl((uint32_t)x)
|
125
|
+
# else
|
126
|
+
# if defined(ntohl)
|
127
|
+
# define _msgpack_be32(x) ntohl(x)
|
128
|
+
# elif defined(_byteswap_ulong) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
129
|
+
# define _msgpack_be32(x) ((uint32_t)_byteswap_ulong((unsigned long)x))
|
130
|
+
# else
|
131
|
+
# define _msgpack_be32(x) \
|
132
|
+
( ((((uint32_t)x) << 24) ) | \
|
133
|
+
((((uint32_t)x) << 8) & 0x00ff0000U ) | \
|
134
|
+
((((uint32_t)x) >> 8) & 0x0000ff00U ) | \
|
135
|
+
((((uint32_t)x) >> 24) ) )
|
136
|
+
# endif
|
137
|
+
# endif
|
138
|
+
|
139
|
+
# if defined(_byteswap_uint64) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
140
|
+
# define _msgpack_be64(x) (_byteswap_uint64(x))
|
141
|
+
# elif defined(bswap_64)
|
142
|
+
# define _msgpack_be64(x) bswap_64(x)
|
143
|
+
# elif defined(__DARWIN_OSSwapInt64)
|
144
|
+
# define _msgpack_be64(x) __DARWIN_OSSwapInt64(x)
|
145
|
+
# else
|
146
|
+
# define _msgpack_be64(x) \
|
147
|
+
( ((((uint64_t)x) << 56) ) | \
|
148
|
+
((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \
|
149
|
+
((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \
|
150
|
+
((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \
|
151
|
+
((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \
|
152
|
+
((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \
|
153
|
+
((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \
|
154
|
+
((((uint64_t)x) >> 56) ) )
|
155
|
+
# endif
|
156
|
+
|
157
|
+
#elif MSGPACK_ENDIAN_BIG_BYTE
|
158
|
+
|
159
|
+
# define _msgpack_be16(x) (x)
|
160
|
+
# define _msgpack_be32(x) (x)
|
161
|
+
# define _msgpack_be64(x) (x)
|
162
|
+
|
163
|
+
#else
|
164
|
+
# error msgpack-c supports only big endian and little endian
|
165
|
+
#endif /* MSGPACK_ENDIAN_LITTLE_BYTE */
|
166
|
+
|
167
|
+
#define _msgpack_load16(cast, from, to) do { \
|
168
|
+
memcpy((cast*)(to), (from), sizeof(cast)); \
|
169
|
+
*(to) = (cast)_msgpack_be16(*(to)); \
|
170
|
+
} while (0);
|
171
|
+
|
172
|
+
#define _msgpack_load32(cast, from, to) do { \
|
173
|
+
memcpy((cast*)(to), (from), sizeof(cast)); \
|
174
|
+
*(to) = (cast)_msgpack_be32(*(to)); \
|
175
|
+
} while (0);
|
176
|
+
#define _msgpack_load64(cast, from, to) do { \
|
177
|
+
memcpy((cast*)(to), (from), sizeof(cast)); \
|
178
|
+
*(to) = (cast)_msgpack_be64(*(to)); \
|
179
|
+
} while (0);
|
180
|
+
|
181
|
+
#define _msgpack_store16(to, num) \
|
182
|
+
do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0)
|
183
|
+
#define _msgpack_store32(to, num) \
|
184
|
+
do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0)
|
185
|
+
#define _msgpack_store64(to, num) \
|
186
|
+
do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0)
|
187
|
+
|
188
|
+
/*
|
189
|
+
#define _msgpack_load16(cast, from) \
|
190
|
+
({ cast val; memcpy(&val, (char*)from, 2); _msgpack_be16(val); })
|
191
|
+
#define _msgpack_load32(cast, from) \
|
192
|
+
({ cast val; memcpy(&val, (char*)from, 4); _msgpack_be32(val); })
|
193
|
+
#define _msgpack_load64(cast, from) \
|
194
|
+
({ cast val; memcpy(&val, (char*)from, 8); _msgpack_be64(val); })
|
195
|
+
*/
|
196
|
+
|
197
|
+
|
198
|
+
#if !defined(__cplusplus) && defined(_MSC_VER)
|
199
|
+
# if !defined(_KERNEL_MODE)
|
200
|
+
# if !defined(FALSE)
|
201
|
+
# define FALSE (0)
|
202
|
+
# endif
|
203
|
+
# if !defined(TRUE)
|
204
|
+
# define TRUE (!FALSE)
|
205
|
+
# endif
|
206
|
+
# endif
|
207
|
+
# if _MSC_VER >= 1800
|
208
|
+
# include <stdbool.h>
|
209
|
+
# else
|
210
|
+
# define bool int
|
211
|
+
# define true TRUE
|
212
|
+
# define false FALSE
|
213
|
+
# endif
|
214
|
+
# define inline __inline
|
215
|
+
#endif
|
216
|
+
|
217
|
+
#ifdef __APPLE__
|
218
|
+
# include <TargetConditionals.h>
|
219
|
+
#endif
|
220
|
+
|
221
|
+
#endif /* msgpack/sysdep.h */
|
@@ -0,0 +1,58 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack for C TimeStamp
|
3
|
+
*
|
4
|
+
* Copyright (C) 2018 KONDO Takatoshi
|
5
|
+
*
|
6
|
+
* Distributed under the Boost Software License, Version 1.0.
|
7
|
+
* (See accompanying file LICENSE_1_0.txt or copy at
|
8
|
+
* http://www.boost.org/LICENSE_1_0.txt)
|
9
|
+
*/
|
10
|
+
#ifndef MSGPACK_TIMESTAMP_H
|
11
|
+
#define MSGPACK_TIMESTAMP_H
|
12
|
+
|
13
|
+
#include <msgpack/object.h>
|
14
|
+
|
15
|
+
#ifdef __cplusplus
|
16
|
+
extern "C" {
|
17
|
+
#endif
|
18
|
+
|
19
|
+
|
20
|
+
typedef struct msgpack_timestamp {
|
21
|
+
int64_t tv_sec;
|
22
|
+
uint32_t tv_nsec;
|
23
|
+
} msgpack_timestamp;
|
24
|
+
|
25
|
+
static inline bool msgpack_object_to_timestamp(const msgpack_object* obj, msgpack_timestamp* ts) {
|
26
|
+
if (obj->type != MSGPACK_OBJECT_EXT) return false;
|
27
|
+
if (obj->via.ext.type != -1) return false;
|
28
|
+
switch (obj->via.ext.size) {
|
29
|
+
case 4:
|
30
|
+
ts->tv_nsec = 0;
|
31
|
+
{
|
32
|
+
uint32_t v;
|
33
|
+
_msgpack_load32(uint32_t, obj->via.ext.ptr, &v);
|
34
|
+
ts->tv_sec = v;
|
35
|
+
}
|
36
|
+
return true;
|
37
|
+
case 8: {
|
38
|
+
uint64_t value;
|
39
|
+
_msgpack_load64(uint64_t, obj->via.ext.ptr, &value);
|
40
|
+
ts->tv_nsec = (uint32_t)(value >> 34);
|
41
|
+
ts->tv_sec = value & 0x00000003ffffffffLL;
|
42
|
+
return true;
|
43
|
+
}
|
44
|
+
case 12:
|
45
|
+
_msgpack_load32(uint32_t, obj->via.ext.ptr, &ts->tv_nsec);
|
46
|
+
_msgpack_load64(int64_t, obj->via.ext.ptr + 4, &ts->tv_sec);
|
47
|
+
return true;
|
48
|
+
default:
|
49
|
+
return false;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
#ifdef __cplusplus
|
55
|
+
}
|
56
|
+
#endif
|
57
|
+
|
58
|
+
#endif /* msgpack/timestamp.h */
|
@@ -0,0 +1,281 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack for C unpacking routine
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
5
|
+
*
|
6
|
+
* Distributed under the Boost Software License, Version 1.0.
|
7
|
+
* (See accompanying file LICENSE_1_0.txt or copy at
|
8
|
+
* http://www.boost.org/LICENSE_1_0.txt)
|
9
|
+
*/
|
10
|
+
#ifndef MSGPACK_UNPACKER_H
|
11
|
+
#define MSGPACK_UNPACKER_H
|
12
|
+
|
13
|
+
#include "zone.h"
|
14
|
+
#include "object.h"
|
15
|
+
#include <string.h>
|
16
|
+
|
17
|
+
#ifdef __cplusplus
|
18
|
+
extern "C" {
|
19
|
+
#endif
|
20
|
+
|
21
|
+
|
22
|
+
/**
|
23
|
+
* @defgroup msgpack_unpack Deserializer
|
24
|
+
* @ingroup msgpack
|
25
|
+
* @{
|
26
|
+
*/
|
27
|
+
|
28
|
+
typedef struct msgpack_unpacked {
|
29
|
+
msgpack_zone* zone;
|
30
|
+
msgpack_object data;
|
31
|
+
} msgpack_unpacked;
|
32
|
+
|
33
|
+
typedef enum {
|
34
|
+
MSGPACK_UNPACK_SUCCESS = 2,
|
35
|
+
MSGPACK_UNPACK_EXTRA_BYTES = 1,
|
36
|
+
MSGPACK_UNPACK_CONTINUE = 0,
|
37
|
+
MSGPACK_UNPACK_PARSE_ERROR = -1,
|
38
|
+
MSGPACK_UNPACK_NOMEM_ERROR = -2
|
39
|
+
} msgpack_unpack_return;
|
40
|
+
|
41
|
+
|
42
|
+
MSGPACK_DLLEXPORT
|
43
|
+
msgpack_unpack_return
|
44
|
+
msgpack_unpack_next(msgpack_unpacked* result,
|
45
|
+
const char* data, size_t len, size_t* off);
|
46
|
+
|
47
|
+
/** @} */
|
48
|
+
|
49
|
+
|
50
|
+
/**
|
51
|
+
* @defgroup msgpack_unpacker Streaming deserializer
|
52
|
+
* @ingroup msgpack
|
53
|
+
* @{
|
54
|
+
*/
|
55
|
+
|
56
|
+
typedef struct msgpack_unpacker {
|
57
|
+
char* buffer;
|
58
|
+
size_t used;
|
59
|
+
size_t free;
|
60
|
+
size_t off;
|
61
|
+
size_t parsed;
|
62
|
+
msgpack_zone* z;
|
63
|
+
size_t initial_buffer_size;
|
64
|
+
void* ctx;
|
65
|
+
} msgpack_unpacker;
|
66
|
+
|
67
|
+
|
68
|
+
#ifndef MSGPACK_UNPACKER_INIT_BUFFER_SIZE
|
69
|
+
#define MSGPACK_UNPACKER_INIT_BUFFER_SIZE (64*1024)
|
70
|
+
#endif
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Initializes a streaming deserializer.
|
74
|
+
* The initialized deserializer must be destroyed by msgpack_unpacker_destroy(msgpack_unpacker*).
|
75
|
+
*/
|
76
|
+
MSGPACK_DLLEXPORT
|
77
|
+
bool msgpack_unpacker_init(msgpack_unpacker* mpac, size_t initial_buffer_size);
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Destroys a streaming deserializer initialized by msgpack_unpacker_init(msgpack_unpacker*, size_t).
|
81
|
+
*/
|
82
|
+
MSGPACK_DLLEXPORT
|
83
|
+
void msgpack_unpacker_destroy(msgpack_unpacker* mpac);
|
84
|
+
|
85
|
+
|
86
|
+
/**
|
87
|
+
* Creates a streaming deserializer.
|
88
|
+
* The created deserializer must be destroyed by msgpack_unpacker_free(msgpack_unpacker*).
|
89
|
+
*/
|
90
|
+
MSGPACK_DLLEXPORT
|
91
|
+
msgpack_unpacker* msgpack_unpacker_new(size_t initial_buffer_size);
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Frees a streaming deserializer created by msgpack_unpacker_new(size_t).
|
95
|
+
*/
|
96
|
+
MSGPACK_DLLEXPORT
|
97
|
+
void msgpack_unpacker_free(msgpack_unpacker* mpac);
|
98
|
+
|
99
|
+
|
100
|
+
#ifndef MSGPACK_UNPACKER_RESERVE_SIZE
|
101
|
+
#define MSGPACK_UNPACKER_RESERVE_SIZE (32*1024)
|
102
|
+
#endif
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Reserves free space of the internal buffer.
|
106
|
+
* Use this function to fill the internal buffer with
|
107
|
+
* msgpack_unpacker_buffer(msgpack_unpacker*),
|
108
|
+
* msgpack_unpacker_buffer_capacity(const msgpack_unpacker*) and
|
109
|
+
* msgpack_unpacker_buffer_consumed(msgpack_unpacker*).
|
110
|
+
*/
|
111
|
+
static inline bool msgpack_unpacker_reserve_buffer(msgpack_unpacker* mpac, size_t size);
|
112
|
+
|
113
|
+
/**
|
114
|
+
* Gets pointer to the free space of the internal buffer.
|
115
|
+
* Use this function to fill the internal buffer with
|
116
|
+
* msgpack_unpacker_reserve_buffer(msgpack_unpacker*, size_t),
|
117
|
+
* msgpack_unpacker_buffer_capacity(const msgpack_unpacker*) and
|
118
|
+
* msgpack_unpacker_buffer_consumed(msgpack_unpacker*).
|
119
|
+
*/
|
120
|
+
static inline char* msgpack_unpacker_buffer(msgpack_unpacker* mpac);
|
121
|
+
|
122
|
+
/**
|
123
|
+
* Gets size of the free space of the internal buffer.
|
124
|
+
* Use this function to fill the internal buffer with
|
125
|
+
* msgpack_unpacker_reserve_buffer(msgpack_unpacker*, size_t),
|
126
|
+
* msgpack_unpacker_buffer(const msgpack_unpacker*) and
|
127
|
+
* msgpack_unpacker_buffer_consumed(msgpack_unpacker*).
|
128
|
+
*/
|
129
|
+
static inline size_t msgpack_unpacker_buffer_capacity(const msgpack_unpacker* mpac);
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Notifies the deserializer that the internal buffer filled.
|
133
|
+
* Use this function to fill the internal buffer with
|
134
|
+
* msgpack_unpacker_reserve_buffer(msgpack_unpacker*, size_t),
|
135
|
+
* msgpack_unpacker_buffer(msgpack_unpacker*) and
|
136
|
+
* msgpack_unpacker_buffer_capacity(const msgpack_unpacker*).
|
137
|
+
*/
|
138
|
+
static inline void msgpack_unpacker_buffer_consumed(msgpack_unpacker* mpac, size_t size);
|
139
|
+
|
140
|
+
|
141
|
+
/**
|
142
|
+
* Deserializes one object.
|
143
|
+
* Returns true if it successes. Otherwise false is returned.
|
144
|
+
* @param pac pointer to an initialized msgpack_unpacked object.
|
145
|
+
*/
|
146
|
+
MSGPACK_DLLEXPORT
|
147
|
+
msgpack_unpack_return msgpack_unpacker_next(msgpack_unpacker* mpac, msgpack_unpacked* pac);
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Deserializes one object and set the number of parsed bytes involved.
|
151
|
+
* Returns true if it successes. Otherwise false is returned.
|
152
|
+
* @param mpac pointer to an initialized msgpack_unpacker object.
|
153
|
+
* @param result pointer to an initialized msgpack_unpacked object.
|
154
|
+
* @param p_bytes pointer to variable that will be set with the number of parsed bytes.
|
155
|
+
*/
|
156
|
+
MSGPACK_DLLEXPORT
|
157
|
+
msgpack_unpack_return msgpack_unpacker_next_with_size(msgpack_unpacker* mpac,
|
158
|
+
msgpack_unpacked* result,
|
159
|
+
size_t *p_bytes);
|
160
|
+
|
161
|
+
/**
|
162
|
+
* Initializes a msgpack_unpacked object.
|
163
|
+
* The initialized object must be destroyed by msgpack_unpacked_destroy(msgpack_unpacker*).
|
164
|
+
* Use the object with msgpack_unpacker_next(msgpack_unpacker*, msgpack_unpacked*) or
|
165
|
+
* msgpack_unpack_next(msgpack_unpacked*, const char*, size_t, size_t*).
|
166
|
+
*/
|
167
|
+
static inline void msgpack_unpacked_init(msgpack_unpacked* result);
|
168
|
+
|
169
|
+
/**
|
170
|
+
* Destroys a streaming deserializer initialized by msgpack_unpacked().
|
171
|
+
*/
|
172
|
+
static inline void msgpack_unpacked_destroy(msgpack_unpacked* result);
|
173
|
+
|
174
|
+
/**
|
175
|
+
* Releases the memory zone from msgpack_unpacked object.
|
176
|
+
* The released zone must be freed by msgpack_zone_free(msgpack_zone*).
|
177
|
+
*/
|
178
|
+
static inline msgpack_zone* msgpack_unpacked_release_zone(msgpack_unpacked* result);
|
179
|
+
|
180
|
+
|
181
|
+
MSGPACK_DLLEXPORT
|
182
|
+
int msgpack_unpacker_execute(msgpack_unpacker* mpac);
|
183
|
+
|
184
|
+
MSGPACK_DLLEXPORT
|
185
|
+
msgpack_object msgpack_unpacker_data(msgpack_unpacker* mpac);
|
186
|
+
|
187
|
+
MSGPACK_DLLEXPORT
|
188
|
+
msgpack_zone* msgpack_unpacker_release_zone(msgpack_unpacker* mpac);
|
189
|
+
|
190
|
+
MSGPACK_DLLEXPORT
|
191
|
+
void msgpack_unpacker_reset_zone(msgpack_unpacker* mpac);
|
192
|
+
|
193
|
+
MSGPACK_DLLEXPORT
|
194
|
+
void msgpack_unpacker_reset(msgpack_unpacker* mpac);
|
195
|
+
|
196
|
+
static inline size_t msgpack_unpacker_message_size(const msgpack_unpacker* mpac);
|
197
|
+
|
198
|
+
|
199
|
+
/** @} */
|
200
|
+
|
201
|
+
|
202
|
+
// obsolete
|
203
|
+
MSGPACK_DLLEXPORT
|
204
|
+
msgpack_unpack_return
|
205
|
+
msgpack_unpack(const char* data, size_t len, size_t* off,
|
206
|
+
msgpack_zone* result_zone, msgpack_object* result);
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
static inline size_t msgpack_unpacker_parsed_size(const msgpack_unpacker* mpac);
|
212
|
+
|
213
|
+
MSGPACK_DLLEXPORT
|
214
|
+
bool msgpack_unpacker_flush_zone(msgpack_unpacker* mpac);
|
215
|
+
|
216
|
+
MSGPACK_DLLEXPORT
|
217
|
+
bool msgpack_unpacker_expand_buffer(msgpack_unpacker* mpac, size_t size);
|
218
|
+
|
219
|
+
static inline bool msgpack_unpacker_reserve_buffer(msgpack_unpacker* mpac, size_t size)
|
220
|
+
{
|
221
|
+
if(mpac->free >= size) { return true; }
|
222
|
+
return msgpack_unpacker_expand_buffer(mpac, size);
|
223
|
+
}
|
224
|
+
|
225
|
+
static inline char* msgpack_unpacker_buffer(msgpack_unpacker* mpac)
|
226
|
+
{
|
227
|
+
return mpac->buffer + mpac->used;
|
228
|
+
}
|
229
|
+
|
230
|
+
static inline size_t msgpack_unpacker_buffer_capacity(const msgpack_unpacker* mpac)
|
231
|
+
{
|
232
|
+
return mpac->free;
|
233
|
+
}
|
234
|
+
|
235
|
+
static inline void msgpack_unpacker_buffer_consumed(msgpack_unpacker* mpac, size_t size)
|
236
|
+
{
|
237
|
+
mpac->used += size;
|
238
|
+
mpac->free -= size;
|
239
|
+
}
|
240
|
+
|
241
|
+
static inline size_t msgpack_unpacker_message_size(const msgpack_unpacker* mpac)
|
242
|
+
{
|
243
|
+
return mpac->parsed - mpac->off + mpac->used;
|
244
|
+
}
|
245
|
+
|
246
|
+
static inline size_t msgpack_unpacker_parsed_size(const msgpack_unpacker* mpac)
|
247
|
+
{
|
248
|
+
return mpac->parsed;
|
249
|
+
}
|
250
|
+
|
251
|
+
|
252
|
+
static inline void msgpack_unpacked_init(msgpack_unpacked* result)
|
253
|
+
{
|
254
|
+
memset(result, 0, sizeof(msgpack_unpacked));
|
255
|
+
}
|
256
|
+
|
257
|
+
static inline void msgpack_unpacked_destroy(msgpack_unpacked* result)
|
258
|
+
{
|
259
|
+
if(result->zone != NULL) {
|
260
|
+
msgpack_zone_free(result->zone);
|
261
|
+
result->zone = NULL;
|
262
|
+
memset(&result->data, 0, sizeof(msgpack_object));
|
263
|
+
}
|
264
|
+
}
|
265
|
+
|
266
|
+
static inline msgpack_zone* msgpack_unpacked_release_zone(msgpack_unpacked* result)
|
267
|
+
{
|
268
|
+
if(result->zone != NULL) {
|
269
|
+
msgpack_zone* z = result->zone;
|
270
|
+
result->zone = NULL;
|
271
|
+
return z;
|
272
|
+
}
|
273
|
+
return NULL;
|
274
|
+
}
|
275
|
+
|
276
|
+
|
277
|
+
#ifdef __cplusplus
|
278
|
+
}
|
279
|
+
#endif
|
280
|
+
|
281
|
+
#endif /* msgpack/unpack.h */
|