msgpack 0.4.7-x86-mingw32 → 0.5.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
|
-
* MessagePack for Ruby
|
2
|
+
* MessagePack for Ruby
|
3
3
|
*
|
4
|
-
* Copyright (C) 2008-
|
4
|
+
* Copyright (C) 2008-2012 FURUHASHI Sadayuki
|
5
5
|
*
|
6
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
* you may not use this file except in compliance with the License.
|
@@ -15,12 +15,16 @@
|
|
15
15
|
* See the License for the specific language governing permissions and
|
16
16
|
* limitations under the License.
|
17
17
|
*/
|
18
|
-
#ifndef
|
19
|
-
#define
|
18
|
+
#ifndef MSGPACK_RUBY_PACKER_CLASS_H__
|
19
|
+
#define MSGPACK_RUBY_PACKER_CLASS_H__
|
20
20
|
|
21
|
-
#include "
|
21
|
+
#include "packer.h"
|
22
22
|
|
23
|
-
|
23
|
+
extern VALUE cMessagePack_Packer;
|
24
24
|
|
25
|
-
|
25
|
+
void MessagePack_Packer_module_init(VALUE mMessagePack);
|
26
|
+
|
27
|
+
VALUE MessagePack_pack(int argc, VALUE* argv);
|
28
|
+
|
29
|
+
#endif
|
26
30
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack for Ruby
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008-2012 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
|
+
#include "buffer_class.h"
|
20
|
+
#include "packer_class.h"
|
21
|
+
#include "unpacker_class.h"
|
22
|
+
#include "core_ext.h"
|
23
|
+
|
24
|
+
void Init_msgpack(void)
|
25
|
+
{
|
26
|
+
VALUE mMessagePack = rb_define_module("MessagePack");
|
27
|
+
|
28
|
+
MessagePack_Buffer_module_init(mMessagePack);
|
29
|
+
MessagePack_Packer_module_init(mMessagePack);
|
30
|
+
MessagePack_Unpacker_module_init(mMessagePack);
|
31
|
+
MessagePack_core_ext_module_init();
|
32
|
+
}
|
33
|
+
|
data/ext/msgpack/rmem.c
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack for Ruby
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008-2012 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
|
+
#include "rmem.h"
|
20
|
+
|
21
|
+
void msgpack_rmem_init(msgpack_rmem_t* pm)
|
22
|
+
{
|
23
|
+
memset(pm, 0, sizeof(msgpack_rmem_t));
|
24
|
+
pm->head.pages = malloc(MSGPACK_RMEM_PAGE_SIZE * 32);
|
25
|
+
pm->head.mask = 0xffffffff; /* all bit is 1 = available */
|
26
|
+
}
|
27
|
+
|
28
|
+
void msgpack_rmem_destroy(msgpack_rmem_t* pm)
|
29
|
+
{
|
30
|
+
msgpack_rmem_chunk_t* c = pm->array_first;
|
31
|
+
msgpack_rmem_chunk_t* cend = pm->array_last;
|
32
|
+
for(; c != cend; c++) {
|
33
|
+
free(c->pages);
|
34
|
+
}
|
35
|
+
free(pm->head.pages);
|
36
|
+
free(pm->array_first);
|
37
|
+
}
|
38
|
+
|
39
|
+
void* _msgpack_rmem_alloc2(msgpack_rmem_t* pm)
|
40
|
+
{
|
41
|
+
msgpack_rmem_chunk_t* c = pm->array_first;
|
42
|
+
msgpack_rmem_chunk_t* last = pm->array_last;
|
43
|
+
for(; c != last; c++) {
|
44
|
+
if(_msgpack_rmem_chunk_available(c)) {
|
45
|
+
void* mem = _msgpack_rmem_chunk_alloc(c);
|
46
|
+
|
47
|
+
/* move to head */
|
48
|
+
msgpack_rmem_chunk_t tmp = pm->head;
|
49
|
+
pm->head = *c;
|
50
|
+
*c = tmp;
|
51
|
+
return mem;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
if(c == pm->array_end) {
|
56
|
+
size_t capacity = c - pm->array_first;
|
57
|
+
size_t length = last - pm->array_first;
|
58
|
+
capacity = (capacity == 0) ? 8 : capacity * 2;
|
59
|
+
msgpack_rmem_chunk_t* array = realloc(pm->array_first, capacity * sizeof(msgpack_rmem_chunk_t));
|
60
|
+
pm->array_first = array;
|
61
|
+
pm->array_last = array + length;
|
62
|
+
pm->array_end = array + capacity;
|
63
|
+
}
|
64
|
+
|
65
|
+
/* allocate new chunk */
|
66
|
+
c = pm->array_last++;
|
67
|
+
|
68
|
+
/* move to head */
|
69
|
+
msgpack_rmem_chunk_t tmp = pm->head;
|
70
|
+
pm->head = *c;
|
71
|
+
*c = tmp;
|
72
|
+
|
73
|
+
pm->head.mask = 0xffffffff & (~1); /* "& (~1)" means first chunk is already allocated */
|
74
|
+
pm->head.pages = malloc(MSGPACK_RMEM_PAGE_SIZE * 32);
|
75
|
+
|
76
|
+
return pm->head.pages;
|
77
|
+
}
|
78
|
+
|
79
|
+
static inline void handle_empty_chunk(msgpack_rmem_t* pm, msgpack_rmem_chunk_t* c)
|
80
|
+
{
|
81
|
+
if(pm->array_first->mask == 0xffffffff) {
|
82
|
+
/* free and move to last */
|
83
|
+
pm->array_last--;
|
84
|
+
free(c->pages);
|
85
|
+
*c = *pm->array_last;
|
86
|
+
return;
|
87
|
+
}
|
88
|
+
|
89
|
+
/* move to first */
|
90
|
+
msgpack_rmem_chunk_t tmp = *pm->array_first;
|
91
|
+
*pm->array_first = *c;
|
92
|
+
*c = tmp;
|
93
|
+
}
|
94
|
+
|
95
|
+
bool _msgpack_rmem_free2(msgpack_rmem_t* pm, void* mem)
|
96
|
+
{
|
97
|
+
/* search from last */
|
98
|
+
msgpack_rmem_chunk_t* c = pm->array_last - 1;
|
99
|
+
msgpack_rmem_chunk_t* before_first = pm->array_first - 1;
|
100
|
+
for(; c != before_first; c--) {
|
101
|
+
if(_msgpack_rmem_chunk_try_free(c, mem)) {
|
102
|
+
if(c != pm->array_first && c->mask == 0xffffffff) {
|
103
|
+
handle_empty_chunk(pm, c);
|
104
|
+
}
|
105
|
+
return true;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
return false;
|
109
|
+
}
|
110
|
+
|
data/ext/msgpack/rmem.h
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack for Ruby
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008-2012 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_RUBY_RMEM_H__
|
19
|
+
#define MSGPACK_RUBY_RMEM_H__
|
20
|
+
|
21
|
+
#include "compat.h"
|
22
|
+
#include "sysdep.h"
|
23
|
+
|
24
|
+
#ifndef MSGPACK_RMEM_PAGE_SIZE
|
25
|
+
#define MSGPACK_RMEM_PAGE_SIZE (4*1024)
|
26
|
+
#endif
|
27
|
+
|
28
|
+
struct msgpack_rmem_t;
|
29
|
+
typedef struct msgpack_rmem_t msgpack_rmem_t;
|
30
|
+
|
31
|
+
struct msgpack_rmem_chunk_t;
|
32
|
+
typedef struct msgpack_rmem_chunk_t msgpack_rmem_chunk_t;
|
33
|
+
|
34
|
+
/*
|
35
|
+
* a chunk contains 32 pages.
|
36
|
+
* size of each buffer is MSGPACK_RMEM_PAGE_SIZE bytes.
|
37
|
+
*/
|
38
|
+
struct msgpack_rmem_chunk_t {
|
39
|
+
unsigned int mask;
|
40
|
+
char* pages;
|
41
|
+
};
|
42
|
+
|
43
|
+
struct msgpack_rmem_t {
|
44
|
+
msgpack_rmem_chunk_t head;
|
45
|
+
msgpack_rmem_chunk_t* array_first;
|
46
|
+
msgpack_rmem_chunk_t* array_last;
|
47
|
+
msgpack_rmem_chunk_t* array_end;
|
48
|
+
};
|
49
|
+
|
50
|
+
/* assert MSGPACK_RMEM_PAGE_SIZE % sysconf(_SC_PAGE_SIZE) == 0 */
|
51
|
+
void msgpack_rmem_init(msgpack_rmem_t* pm);
|
52
|
+
|
53
|
+
void msgpack_rmem_destroy(msgpack_rmem_t* pm);
|
54
|
+
|
55
|
+
void* _msgpack_rmem_alloc2(msgpack_rmem_t* pm);
|
56
|
+
|
57
|
+
#define _msgpack_rmem_chunk_available(c) ((c)->mask != 0)
|
58
|
+
|
59
|
+
static inline void* _msgpack_rmem_chunk_alloc(msgpack_rmem_chunk_t* c)
|
60
|
+
{
|
61
|
+
_msgpack_bsp32(pos, c->mask);
|
62
|
+
(c)->mask &= ~(1 << pos);
|
63
|
+
return ((char*)(c)->pages) + (pos * (MSGPACK_RMEM_PAGE_SIZE));
|
64
|
+
}
|
65
|
+
|
66
|
+
static inline bool _msgpack_rmem_chunk_try_free(msgpack_rmem_chunk_t* c, void* mem)
|
67
|
+
{
|
68
|
+
ptrdiff_t pdiff = ((char*)(mem)) - ((char*)(c)->pages);
|
69
|
+
if(0 <= pdiff && pdiff < MSGPACK_RMEM_PAGE_SIZE * 32) {
|
70
|
+
size_t pos = pdiff / MSGPACK_RMEM_PAGE_SIZE;
|
71
|
+
(c)->mask |= (1 << pos);
|
72
|
+
return true;
|
73
|
+
}
|
74
|
+
return false;
|
75
|
+
}
|
76
|
+
|
77
|
+
static inline void* msgpack_rmem_alloc(msgpack_rmem_t* pm)
|
78
|
+
{
|
79
|
+
if(_msgpack_rmem_chunk_available(&pm->head)) {
|
80
|
+
return _msgpack_rmem_chunk_alloc(&pm->head);
|
81
|
+
}
|
82
|
+
return _msgpack_rmem_alloc2(pm);
|
83
|
+
}
|
84
|
+
|
85
|
+
bool _msgpack_rmem_free2(msgpack_rmem_t* pm, void* mem);
|
86
|
+
|
87
|
+
static inline bool msgpack_rmem_free(msgpack_rmem_t* pm, void* mem)
|
88
|
+
{
|
89
|
+
if(_msgpack_rmem_chunk_try_free(&pm->head, mem)) {
|
90
|
+
return true;
|
91
|
+
}
|
92
|
+
if(pm->array_last == pm->array_end) {
|
93
|
+
return false;
|
94
|
+
}
|
95
|
+
return _msgpack_rmem_free2(pm, mem);
|
96
|
+
}
|
97
|
+
|
98
|
+
|
99
|
+
#endif
|
100
|
+
|
@@ -0,0 +1,115 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack for Ruby
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008-2012 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_RUBY_SYSDEP_H__
|
19
|
+
#define MSGPACK_RUBY_SYSDEP_H__
|
20
|
+
|
21
|
+
#include "sysdep_types.h"
|
22
|
+
#include "sysdep_endian.h"
|
23
|
+
|
24
|
+
|
25
|
+
#define UNUSED(var) ((void)var)
|
26
|
+
|
27
|
+
|
28
|
+
#ifdef __LITTLE_ENDIAN__
|
29
|
+
|
30
|
+
/* _msgpack_be16 */
|
31
|
+
#ifdef _WIN32
|
32
|
+
# if defined(ntohs)
|
33
|
+
# define _msgpack_be16(x) ntohs(x)
|
34
|
+
# elif defined(_byteswap_ushort) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
35
|
+
# define _msgpack_be16(x) ((uint16_t)_byteswap_ushort((unsigned short)x))
|
36
|
+
# else
|
37
|
+
# define _msgpack_be16(x) ( \
|
38
|
+
((((uint16_t)x) << 8) ) | \
|
39
|
+
((((uint16_t)x) >> 8) ) )
|
40
|
+
# endif
|
41
|
+
#else
|
42
|
+
# define _msgpack_be16(x) ntohs(x)
|
43
|
+
#endif
|
44
|
+
|
45
|
+
/* _msgpack_be32 */
|
46
|
+
#ifdef _WIN32
|
47
|
+
# if defined(ntohl)
|
48
|
+
# define _msgpack_be32(x) ntohl(x)
|
49
|
+
# elif defined(_byteswap_ulong) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
50
|
+
# define _msgpack_be32(x) ((uint32_t)_byteswap_ulong((unsigned long)x))
|
51
|
+
# else
|
52
|
+
# define _msgpack_be32(x) \
|
53
|
+
( ((((uint32_t)x) << 24) ) | \
|
54
|
+
((((uint32_t)x) << 8) & 0x00ff0000U ) | \
|
55
|
+
((((uint32_t)x) >> 8) & 0x0000ff00U ) | \
|
56
|
+
((((uint32_t)x) >> 24) ) )
|
57
|
+
# endif
|
58
|
+
#else
|
59
|
+
# define _msgpack_be32(x) ntohl(x)
|
60
|
+
#endif
|
61
|
+
|
62
|
+
/* _msgpack_be64 */
|
63
|
+
#if defined(_byteswap_uint64) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
64
|
+
# define _msgpack_be64(x) (_byteswap_uint64(x))
|
65
|
+
#elif defined(bswap_64)
|
66
|
+
# define _msgpack_be64(x) bswap_64(x)
|
67
|
+
#elif defined(__DARWIN_OSSwapInt64)
|
68
|
+
# define _msgpack_be64(x) __DARWIN_OSSwapInt64(x)
|
69
|
+
#else
|
70
|
+
#define _msgpack_be64(x) \
|
71
|
+
( ((((uint64_t)x) << 56) ) | \
|
72
|
+
((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \
|
73
|
+
((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \
|
74
|
+
((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \
|
75
|
+
((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \
|
76
|
+
((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \
|
77
|
+
((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \
|
78
|
+
((((uint64_t)x) >> 56) ) )
|
79
|
+
#endif
|
80
|
+
|
81
|
+
#else /* big endian */
|
82
|
+
#define _msgpack_be16(x) (x)
|
83
|
+
#define _msgpack_be32(x) (x)
|
84
|
+
#define _msgpack_be64(x) (x)
|
85
|
+
|
86
|
+
#endif
|
87
|
+
|
88
|
+
|
89
|
+
/* _msgpack_be_float */
|
90
|
+
#define _msgpack_be_float(x) _msgpack_be32(x)
|
91
|
+
|
92
|
+
/* _msgpack_be_double */
|
93
|
+
#if defined(__arm__) && !(__ARM_EABI__)
|
94
|
+
/* ARM OABI */
|
95
|
+
#define _msgpack_be_double(x) \
|
96
|
+
( (((x) & 0xFFFFFFFFUL) << 32UL) | ((x) >> 32UL) )
|
97
|
+
#else
|
98
|
+
/* the other ABI */
|
99
|
+
#define _msgpack_be_double(x) _msgpack_be64(x)
|
100
|
+
#endif
|
101
|
+
|
102
|
+
/* _msgpack_bsp32 */
|
103
|
+
#if defined(_MSC_VER)
|
104
|
+
#define _msgpack_bsp32(name, val) \
|
105
|
+
long name; \
|
106
|
+
_BitScanForward(&name, val)
|
107
|
+
#else
|
108
|
+
#define _msgpack_bsp32(name, val) \
|
109
|
+
int name = __builtin_ctz(val)
|
110
|
+
/* TODO default impl for _msgpack_bsp32 */
|
111
|
+
#endif
|
112
|
+
|
113
|
+
|
114
|
+
#endif
|
115
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack for Ruby
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008-2012 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_RUBY_SYSDEP_ENDIAN_H__
|
19
|
+
#define MSGPACK_RUBY_SYSDEP_ENDIAN_H__
|
20
|
+
|
21
|
+
/* including arpa/inet.h requires an extra dll on win32 */
|
22
|
+
#ifndef _WIN32
|
23
|
+
#include <arpa/inet.h> /* __BYTE_ORDER */
|
24
|
+
#endif
|
25
|
+
|
26
|
+
/*
|
27
|
+
* Use following command to add consitions here:
|
28
|
+
* cpp -dM `echo "#include <arpa/inet.h>" > test.c; echo test.c` | grep ENDIAN
|
29
|
+
*/
|
30
|
+
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) /* Mac OS X */
|
31
|
+
# if defined(_LITTLE_ENDIAN) \
|
32
|
+
|| ( defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) \
|
33
|
+
&& __BYTE_ORDER == __LITTLE_ENDIAN ) /* Linux */ \
|
34
|
+
|| ( defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) \
|
35
|
+
&& __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ) /* Solaris */
|
36
|
+
# define __LITTLE_ENDIAN__
|
37
|
+
# elif defined(_BIG_ENDIAN) \
|
38
|
+
|| (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) \
|
39
|
+
&& __BYTE_ORDER == __BIG_ENDIAN) /* Linux */ \
|
40
|
+
|| (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) \
|
41
|
+
&& __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) /* Solaris */
|
42
|
+
# define __BIG_ENDIAN__
|
43
|
+
# elif defined(_WIN32) /* Win32 */
|
44
|
+
# define __LITTLE_ENDIAN__
|
45
|
+
# endif
|
46
|
+
#endif
|
47
|
+
|
48
|
+
|
49
|
+
#endif
|
50
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack for Ruby
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008-2012 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_RUBY_SYSDEP_TYPES_H__
|
19
|
+
#define MSGPACK_RUBY_SYSDEP_TYPES_H__
|
20
|
+
|
21
|
+
#include <string.h>
|
22
|
+
#include <stdlib.h>
|
23
|
+
|
24
|
+
#include <stddef.h>
|
25
|
+
|
26
|
+
#if defined(_MSC_VER) && _MSC_VER < 1600
|
27
|
+
typedef __int8 int8_t;
|
28
|
+
typedef unsigned __int8 uint8_t;
|
29
|
+
typedef __int16 int16_t;
|
30
|
+
typedef unsigned __int16 uint16_t;
|
31
|
+
typedef __int32 int32_t;
|
32
|
+
typedef unsigned __int32 uint32_t;
|
33
|
+
typedef __int64 int64_t;
|
34
|
+
typedef unsigned __int64 uint64_t;
|
35
|
+
|
36
|
+
#elif defined(_MSC_VER) // && _MSC_VER >= 1600
|
37
|
+
#include <stdint.h>
|
38
|
+
|
39
|
+
#else
|
40
|
+
#include <stdint.h>
|
41
|
+
#include <stdbool.h>
|
42
|
+
#endif
|
43
|
+
|
44
|
+
|
45
|
+
#endif
|
46
|
+
|