gitlab-cbor 1.0.0

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.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.gitlab-ci.yml +44 -0
  4. data/.travis.yml +24 -0
  5. data/CHANGELOG.md +30 -0
  6. data/ChangeLog +106 -0
  7. data/Gemfile +11 -0
  8. data/README.rdoc +191 -0
  9. data/Rakefile +97 -0
  10. data/ci/test.rb +31 -0
  11. data/doclib/cbor/buffer.rb +193 -0
  12. data/doclib/cbor/core_ext.rb +133 -0
  13. data/doclib/cbor/error.rb +14 -0
  14. data/doclib/cbor/packer.rb +133 -0
  15. data/doclib/cbor/simple.rb +15 -0
  16. data/doclib/cbor/tagged.rb +16 -0
  17. data/doclib/cbor/unpacker.rb +138 -0
  18. data/doclib/cbor.rb +80 -0
  19. data/ext/cbor/buffer.c +693 -0
  20. data/ext/cbor/buffer.h +484 -0
  21. data/ext/cbor/buffer_class.c +561 -0
  22. data/ext/cbor/buffer_class.h +41 -0
  23. data/ext/cbor/cbor.h +69 -0
  24. data/ext/cbor/compat.h +147 -0
  25. data/ext/cbor/core_ext.c +199 -0
  26. data/ext/cbor/core_ext.h +35 -0
  27. data/ext/cbor/extconf.rb +29 -0
  28. data/ext/cbor/packer.c +169 -0
  29. data/ext/cbor/packer.h +370 -0
  30. data/ext/cbor/packer_class.c +345 -0
  31. data/ext/cbor/packer_class.h +40 -0
  32. data/ext/cbor/rbinit.c +57 -0
  33. data/ext/cbor/renamer.h +56 -0
  34. data/ext/cbor/rmem.c +103 -0
  35. data/ext/cbor/rmem.h +118 -0
  36. data/ext/cbor/sysdep.h +139 -0
  37. data/ext/cbor/sysdep_endian.h +59 -0
  38. data/ext/cbor/sysdep_types.h +55 -0
  39. data/ext/cbor/unpacker.c +787 -0
  40. data/ext/cbor/unpacker.h +135 -0
  41. data/ext/cbor/unpacker_class.c +483 -0
  42. data/ext/cbor/unpacker_class.h +39 -0
  43. data/gitlab-cbor.gemspec +27 -0
  44. data/lib/cbor/version.rb +3 -0
  45. data/lib/cbor.rb +6 -0
  46. data/spec/buffer_io_spec.rb +260 -0
  47. data/spec/buffer_spec.rb +576 -0
  48. data/spec/cases.cbor +0 -0
  49. data/spec/cases.cbor_stream +0 -0
  50. data/spec/cases.json +1 -0
  51. data/spec/cases.msg +0 -0
  52. data/spec/cases_compact.msg +0 -0
  53. data/spec/cases_spec.rb +39 -0
  54. data/spec/format_spec.rb +603 -0
  55. data/spec/packer_spec.rb +127 -0
  56. data/spec/random_compat.rb +24 -0
  57. data/spec/spec_helper.rb +68 -0
  58. data/spec/unpacker_spec.rb +260 -0
  59. metadata +189 -0
@@ -0,0 +1,40 @@
1
+ /*
2
+ * CBOR for Ruby
3
+ *
4
+ * Copyright (C) 2013 Carsten Bormann
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License").
7
+ *
8
+ * Based on:
9
+ ***********/
10
+ /*
11
+ * MessagePack for Ruby
12
+ *
13
+ * Copyright (C) 2008-2013 Sadayuki Furuhashi
14
+ *
15
+ * Licensed under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License.
17
+ * You may obtain a copy of the License at
18
+ *
19
+ * http://www.apache.org/licenses/LICENSE-2.0
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software
22
+ * distributed under the License is distributed on an "AS IS" BASIS,
23
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ * See the License for the specific language governing permissions and
25
+ * limitations under the License.
26
+ */
27
+ #ifndef MSGPACK_RUBY_PACKER_CLASS_H__
28
+ #define MSGPACK_RUBY_PACKER_CLASS_H__
29
+
30
+ #include "packer.h"
31
+
32
+ extern VALUE cMessagePack_Packer;
33
+
34
+ msgpack_packer_t* MessagePack_Packer_get(VALUE self);
35
+
36
+ void MessagePack_Packer_module_init(VALUE mMessagePack);
37
+
38
+ VALUE MessagePack_pack(int argc, VALUE* argv);
39
+
40
+ #endif
data/ext/cbor/rbinit.c ADDED
@@ -0,0 +1,57 @@
1
+ /*
2
+ * CBOR for Ruby
3
+ *
4
+ * Copyright (C) 2013 Carsten Bormann
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License").
7
+ *
8
+ * Based on:
9
+ ***********/
10
+ /*
11
+ * MessagePack for Ruby
12
+ *
13
+ * Copyright (C) 2008-2013 Sadayuki Furuhashi
14
+ *
15
+ * Licensed under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License.
17
+ * You may obtain a copy of the License at
18
+ *
19
+ * http://www.apache.org/licenses/LICENSE-2.0
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software
22
+ * distributed under the License is distributed on an "AS IS" BASIS,
23
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ * See the License for the specific language governing permissions and
25
+ * limitations under the License.
26
+ */
27
+
28
+ #include "buffer_class.h"
29
+ #include "packer_class.h"
30
+ #include "unpacker_class.h"
31
+ #include "core_ext.h"
32
+
33
+
34
+ VALUE rb_cCBOR_Tagged;
35
+ VALUE rb_cCBOR_Simple;
36
+
37
+ void Init_cbor(void)
38
+ {
39
+ VALUE mMessagePack = rb_define_module("CBOR");
40
+
41
+ rb_cCBOR_Tagged = rb_struct_define(NULL, "tag", "value", NULL);
42
+ rb_define_const(mMessagePack, "Tagged", rb_cCBOR_Tagged);
43
+ rb_cCBOR_Simple = rb_struct_define(NULL, "value", NULL);
44
+ rb_define_const(mMessagePack, "Simple", rb_cCBOR_Simple);
45
+
46
+ /* CBOR tag numbers accepted by the decode option reconstruct_from_tags:,
47
+ so callers can write reconstruct_from_tags: [CBOR::TAG_REGEXP] instead of
48
+ a bare integer. */
49
+ rb_define_const(mMessagePack, "TAG_URI", INT2FIX(TAG_URI));
50
+ rb_define_const(mMessagePack, "TAG_REGEXP", INT2FIX(TAG_RE));
51
+
52
+ MessagePack_Buffer_module_init(mMessagePack);
53
+ MessagePack_Packer_module_init(mMessagePack);
54
+ MessagePack_Unpacker_module_init(mMessagePack);
55
+ MessagePack_core_ext_module_init();
56
+ }
57
+
@@ -0,0 +1,56 @@
1
+ #define MessagePack_Buffer_initialize CBOR_Buffer_initialize
2
+ #define MessagePack_Buffer_module_init CBOR_Buffer_module_init
3
+ #define MessagePack_Buffer_wrap CBOR_Buffer_wrap
4
+ #define MessagePack_Packer_module_init CBOR_Packer_module_init
5
+ #define MessagePack_Unpacker_module_init CBOR_Unpacker_module_init
6
+ #define MessagePack_core_ext_module_init CBOR_core_ext_module_init
7
+ #define MessagePack_pack CBOR_pack
8
+ #define MessagePack_unpack CBOR_unpack
9
+ #define _msgpack_buffer_append_long_string _CBOR_buffer_append_long_string
10
+ #define _msgpack_buffer_expand _CBOR_buffer_expand
11
+ #define _msgpack_buffer_feed_from_io _CBOR_buffer_feed_from_io
12
+ #define _msgpack_buffer_read_all2 _CBOR_buffer_read_all2
13
+ #define _msgpack_buffer_read_from_io_to_string _CBOR_buffer_read_from_io_to_string
14
+ #define _msgpack_buffer_shift_chunk _CBOR_buffer_shift_chunk
15
+ #define _msgpack_buffer_skip_from_io _CBOR_buffer_skip_from_io
16
+ #define _msgpack_rmem_alloc2 _CBOR_rmem_alloc2
17
+ #define _msgpack_rmem_chunk_free _CBOR_rmem_chunk_free
18
+ #define cMessagePack_Buffer cCBOR_Buffer
19
+ #define cMessagePack_Packer cCBOR_Packer
20
+ #define cMessagePack_Unpacker cCBOR_Unpacker
21
+ #define msgpack_buffer_all_as_string CBOR_buffer_all_as_string
22
+ #define msgpack_buffer_all_as_string_array CBOR_buffer_all_as_string_array
23
+ #define msgpack_buffer_all_readable_size CBOR_buffer_all_readable_size
24
+ #define msgpack_buffer_clear CBOR_buffer_clear
25
+ #define msgpack_buffer_destroy CBOR_buffer_destroy
26
+ #define msgpack_buffer_flush_to_io CBOR_buffer_flush_to_io
27
+ #define msgpack_buffer_init CBOR_buffer_init
28
+ #define msgpack_buffer_mark CBOR_buffer_mark
29
+ #define msgpack_buffer_read_nonblock CBOR_buffer_read_nonblock
30
+ #define msgpack_buffer_read_to_string_nonblock CBOR_buffer_read_to_string_nonblock
31
+ #define msgpack_buffer_static_destroy CBOR_buffer_static_destroy
32
+ #define msgpack_buffer_static_init CBOR_buffer_static_init
33
+ #define msgpack_packer_destroy CBOR_packer_destroy
34
+ #define msgpack_packer_init CBOR_packer_init
35
+ #define msgpack_packer_mark CBOR_packer_mark
36
+ #define msgpack_packer_reset CBOR_packer_reset
37
+ #define msgpack_packer_static_destroy CBOR_packer_static_destroy
38
+ #define msgpack_packer_static_init CBOR_packer_static_init
39
+ #define msgpack_packer_write_array_value CBOR_packer_write_array_value
40
+ #define msgpack_packer_write_hash_value CBOR_packer_write_hash_value
41
+ #define msgpack_packer_write_value CBOR_packer_write_value
42
+ #define msgpack_rmem_destroy CBOR_rmem_destroy
43
+ #define msgpack_rmem_init CBOR_rmem_init
44
+ #define msgpack_unpacker_destroy CBOR_unpacker_destroy
45
+ #define msgpack_unpacker_init CBOR_unpacker_init
46
+ #define msgpack_unpacker_mark CBOR_unpacker_mark
47
+ #define msgpack_unpacker_peek_next_object_type CBOR_unpacker_peek_next_object_type
48
+ #define msgpack_unpacker_read CBOR_unpacker_read
49
+ #define msgpack_unpacker_read_array_header CBOR_unpacker_read_array_header
50
+ #define msgpack_unpacker_read_container_header CBOR_unpacker_read_container_header
51
+ #define msgpack_unpacker_read_map_header CBOR_unpacker_read_map_header
52
+ #define msgpack_unpacker_reset CBOR_unpacker_reset
53
+ #define msgpack_unpacker_skip CBOR_unpacker_skip
54
+ #define msgpack_unpacker_skip_nil CBOR_unpacker_skip_nil
55
+ #define msgpack_unpacker_static_destroy CBOR_unpacker_static_destroy
56
+ #define msgpack_unpacker_static_init CBOR_unpacker_static_init
data/ext/cbor/rmem.c ADDED
@@ -0,0 +1,103 @@
1
+ /*
2
+ * CBOR for Ruby
3
+ *
4
+ * Copyright (C) 2013 Carsten Bormann
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License").
7
+ *
8
+ * Based on:
9
+ ***********/
10
+ /*
11
+ * MessagePack for Ruby
12
+ *
13
+ * Copyright (C) 2008-2013 Sadayuki Furuhashi
14
+ *
15
+ * Licensed under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License.
17
+ * You may obtain a copy of the License at
18
+ *
19
+ * http://www.apache.org/licenses/LICENSE-2.0
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software
22
+ * distributed under the License is distributed on an "AS IS" BASIS,
23
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ * See the License for the specific language governing permissions and
25
+ * limitations under the License.
26
+ */
27
+
28
+ #include "rmem.h"
29
+
30
+ void msgpack_rmem_init(msgpack_rmem_t* pm)
31
+ {
32
+ memset(pm, 0, sizeof(msgpack_rmem_t));
33
+ pm->head.pages = malloc(MSGPACK_RMEM_PAGE_SIZE * 32);
34
+ pm->head.mask = 0xffffffff; /* all bit is 1 = available */
35
+ }
36
+
37
+ void msgpack_rmem_destroy(msgpack_rmem_t* pm)
38
+ {
39
+ msgpack_rmem_chunk_t* c = pm->array_first;
40
+ msgpack_rmem_chunk_t* cend = pm->array_last;
41
+ for(; c != cend; c++) {
42
+ free(c->pages);
43
+ }
44
+ free(pm->head.pages);
45
+ free(pm->array_first);
46
+ }
47
+
48
+ void* _msgpack_rmem_alloc2(msgpack_rmem_t* pm)
49
+ {
50
+ msgpack_rmem_chunk_t* c = pm->array_first;
51
+ msgpack_rmem_chunk_t* last = pm->array_last;
52
+ for(; c != last; c++) {
53
+ if(_msgpack_rmem_chunk_available(c)) {
54
+ void* mem = _msgpack_rmem_chunk_alloc(c);
55
+
56
+ /* move to head */
57
+ msgpack_rmem_chunk_t tmp = pm->head;
58
+ pm->head = *c;
59
+ *c = tmp;
60
+ return mem;
61
+ }
62
+ }
63
+
64
+ if(c == pm->array_end) {
65
+ size_t capacity = c - pm->array_first;
66
+ size_t length = last - pm->array_first;
67
+ capacity = (capacity == 0) ? 8 : capacity * 2;
68
+ msgpack_rmem_chunk_t* array = realloc(pm->array_first, capacity * sizeof(msgpack_rmem_chunk_t));
69
+ pm->array_first = array;
70
+ pm->array_last = array + length;
71
+ pm->array_end = array + capacity;
72
+ }
73
+
74
+ /* allocate new chunk */
75
+ c = pm->array_last++;
76
+
77
+ /* move to head */
78
+ msgpack_rmem_chunk_t tmp = pm->head;
79
+ pm->head = *c;
80
+ *c = tmp;
81
+
82
+ pm->head.mask = 0xffffffff & (~1); /* "& (~1)" means first chunk is already allocated */
83
+ pm->head.pages = malloc(MSGPACK_RMEM_PAGE_SIZE * 32);
84
+
85
+ return pm->head.pages;
86
+ }
87
+
88
+ void _msgpack_rmem_chunk_free(msgpack_rmem_t* pm, msgpack_rmem_chunk_t* c)
89
+ {
90
+ if(pm->array_first->mask == 0xffffffff) {
91
+ /* free and move to last */
92
+ pm->array_last--;
93
+ free(c->pages);
94
+ *c = *pm->array_last;
95
+ return;
96
+ }
97
+
98
+ /* move to first */
99
+ msgpack_rmem_chunk_t tmp = *pm->array_first;
100
+ *pm->array_first = *c;
101
+ *c = tmp;
102
+ }
103
+
data/ext/cbor/rmem.h ADDED
@@ -0,0 +1,118 @@
1
+ /*
2
+ * CBOR for Ruby
3
+ *
4
+ * Copyright (C) 2013 Carsten Bormann
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License").
7
+ *
8
+ * Based on:
9
+ ***********/
10
+ /*
11
+ * MessagePack for Ruby
12
+ *
13
+ * Copyright (C) 2008-2013 Sadayuki Furuhashi
14
+ *
15
+ * Licensed under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License.
17
+ * You may obtain a copy of the License at
18
+ *
19
+ * http://www.apache.org/licenses/LICENSE-2.0
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software
22
+ * distributed under the License is distributed on an "AS IS" BASIS,
23
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ * See the License for the specific language governing permissions and
25
+ * limitations under the License.
26
+ */
27
+ #ifndef MSGPACK_RUBY_RMEM_H__
28
+ #define MSGPACK_RUBY_RMEM_H__
29
+
30
+ #include "compat.h"
31
+ #include "sysdep.h"
32
+
33
+ #ifndef MSGPACK_RMEM_PAGE_SIZE
34
+ #define MSGPACK_RMEM_PAGE_SIZE (4*1024)
35
+ #endif
36
+
37
+ struct msgpack_rmem_t;
38
+ typedef struct msgpack_rmem_t msgpack_rmem_t;
39
+
40
+ struct msgpack_rmem_chunk_t;
41
+ typedef struct msgpack_rmem_chunk_t msgpack_rmem_chunk_t;
42
+
43
+ /*
44
+ * a chunk contains 32 pages.
45
+ * size of each buffer is MSGPACK_RMEM_PAGE_SIZE bytes.
46
+ */
47
+ struct msgpack_rmem_chunk_t {
48
+ unsigned int mask;
49
+ char* pages;
50
+ };
51
+
52
+ struct msgpack_rmem_t {
53
+ msgpack_rmem_chunk_t head;
54
+ msgpack_rmem_chunk_t* array_first;
55
+ msgpack_rmem_chunk_t* array_last;
56
+ msgpack_rmem_chunk_t* array_end;
57
+ };
58
+
59
+ /* assert MSGPACK_RMEM_PAGE_SIZE % sysconf(_SC_PAGE_SIZE) == 0 */
60
+ void msgpack_rmem_init(msgpack_rmem_t* pm);
61
+
62
+ void msgpack_rmem_destroy(msgpack_rmem_t* pm);
63
+
64
+ void* _msgpack_rmem_alloc2(msgpack_rmem_t* pm);
65
+
66
+ #define _msgpack_rmem_chunk_available(c) ((c)->mask != 0)
67
+
68
+ static inline void* _msgpack_rmem_chunk_alloc(msgpack_rmem_chunk_t* c)
69
+ {
70
+ _msgpack_bsp32(pos, c->mask);
71
+ (c)->mask &= ~(1 << pos);
72
+ return ((char*)(c)->pages) + (pos * (MSGPACK_RMEM_PAGE_SIZE));
73
+ }
74
+
75
+ static inline bool _msgpack_rmem_chunk_try_free(msgpack_rmem_chunk_t* c, void* mem)
76
+ {
77
+ ptrdiff_t pdiff = ((char*)(mem)) - ((char*)(c)->pages);
78
+ if(0 <= pdiff && pdiff < MSGPACK_RMEM_PAGE_SIZE * 32) {
79
+ size_t pos = pdiff / MSGPACK_RMEM_PAGE_SIZE;
80
+ (c)->mask |= (1 << pos);
81
+ return true;
82
+ }
83
+ return false;
84
+ }
85
+
86
+ static inline void* msgpack_rmem_alloc(msgpack_rmem_t* pm)
87
+ {
88
+ if(_msgpack_rmem_chunk_available(&pm->head)) {
89
+ return _msgpack_rmem_chunk_alloc(&pm->head);
90
+ }
91
+ return _msgpack_rmem_alloc2(pm);
92
+ }
93
+
94
+ void _msgpack_rmem_chunk_free(msgpack_rmem_t* pm, msgpack_rmem_chunk_t* c);
95
+
96
+ static inline bool msgpack_rmem_free(msgpack_rmem_t* pm, void* mem)
97
+ {
98
+ if(_msgpack_rmem_chunk_try_free(&pm->head, mem)) {
99
+ return true;
100
+ }
101
+
102
+ /* search from last */
103
+ msgpack_rmem_chunk_t* c = pm->array_last - 1;
104
+ msgpack_rmem_chunk_t* before_first = pm->array_first - 1;
105
+ for(; c != before_first; c--) {
106
+ if(_msgpack_rmem_chunk_try_free(c, mem)) {
107
+ if(c != pm->array_first && c->mask == 0xffffffff) {
108
+ _msgpack_rmem_chunk_free(pm, c);
109
+ }
110
+ return true;
111
+ }
112
+ }
113
+ return false;
114
+ }
115
+
116
+
117
+ #endif
118
+
data/ext/cbor/sysdep.h ADDED
@@ -0,0 +1,139 @@
1
+ /*
2
+ * CBOR for Ruby
3
+ *
4
+ * Copyright (C) 2013 Carsten Bormann
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License").
7
+ *
8
+ * Based on:
9
+ ***********/
10
+ /*
11
+ * MessagePack for Ruby
12
+ *
13
+ * Copyright (C) 2008-2013 Sadayuki Furuhashi
14
+ *
15
+ * Licensed under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License.
17
+ * You may obtain a copy of the License at
18
+ *
19
+ * http://www.apache.org/licenses/LICENSE-2.0
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software
22
+ * distributed under the License is distributed on an "AS IS" BASIS,
23
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ * See the License for the specific language governing permissions and
25
+ * limitations under the License.
26
+ */
27
+ #ifndef MSGPACK_RUBY_SYSDEP_H__
28
+ #define MSGPACK_RUBY_SYSDEP_H__
29
+
30
+ #include "renamer.h"
31
+
32
+ #include "sysdep_types.h"
33
+ #include "sysdep_endian.h"
34
+
35
+
36
+ #define UNUSED(var) ((void)var)
37
+
38
+
39
+ #ifdef __LITTLE_ENDIAN__
40
+
41
+ /* _msgpack_be16 */
42
+ #ifdef _WIN32
43
+ # if defined(ntohs)
44
+ # define _msgpack_be16(x) ntohs(x)
45
+ # elif defined(_byteswap_ushort) || (defined(_MSC_VER) && _MSC_VER >= 1400)
46
+ # define _msgpack_be16(x) ((uint16_t)_byteswap_ushort((unsigned short)x))
47
+ # else
48
+ # define _msgpack_be16(x) ( \
49
+ ((((uint16_t)x) << 8) & 0x0000ff00U ) | \
50
+ ((((uint16_t)x) >> 8) & 0x000000ffU ) )
51
+ # endif
52
+ #else
53
+ # define _msgpack_be16(x) ntohs(x)
54
+ #endif
55
+
56
+ /* _msgpack_be32 */
57
+ #ifdef _WIN32
58
+ # if defined(ntohl)
59
+ # define _msgpack_be32(x) ntohl(x)
60
+ # elif defined(_byteswap_ulong) || (defined(_MSC_VER) && _MSC_VER >= 1400)
61
+ # define _msgpack_be32(x) ((uint32_t)_byteswap_ulong((unsigned long)x))
62
+ # else
63
+ # define _msgpack_be32(x) \
64
+ ( ((((uint32_t)x) << 24) ) | \
65
+ ((((uint32_t)x) << 8) & 0x00ff0000U ) | \
66
+ ((((uint32_t)x) >> 8) & 0x0000ff00U ) | \
67
+ ((((uint32_t)x) >> 24) ) )
68
+ # endif
69
+ #else
70
+ # define _msgpack_be32(x) ntohl(x)
71
+ #endif
72
+
73
+ /* _msgpack_be64 */
74
+ #if defined(_byteswap_uint64) || (defined(_MSC_VER) && _MSC_VER >= 1400)
75
+ # define _msgpack_be64(x) (_byteswap_uint64(x))
76
+ #elif defined(bswap_64)
77
+ # define _msgpack_be64(x) bswap_64(x)
78
+ #elif defined(__DARWIN_OSSwapInt64)
79
+ # define _msgpack_be64(x) __DARWIN_OSSwapInt64(x)
80
+ #else
81
+ #define _msgpack_be64(x) \
82
+ ( ((((uint64_t)x) << 56) ) | \
83
+ ((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \
84
+ ((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \
85
+ ((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \
86
+ ((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \
87
+ ((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \
88
+ ((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \
89
+ ((((uint64_t)x) >> 56) ) )
90
+ #endif
91
+
92
+ #else /* big endian */
93
+ #define _msgpack_be16(x) (x)
94
+ #define _msgpack_be32(x) (x)
95
+ #define _msgpack_be64(x) (x)
96
+
97
+ #endif
98
+
99
+
100
+ /* _msgpack_be_float */
101
+ #define _msgpack_be_float(x) _msgpack_be32(x)
102
+
103
+ /* _msgpack_be_double */
104
+ #if defined(__arm__) && !(__ARM_EABI__)
105
+ /* ARM OABI */
106
+ #define _msgpack_be_double(x) \
107
+ ( (((x) & 0xFFFFFFFFUL) << 32UL) | ((x) >> 32UL) )
108
+ #else
109
+ /* the other ABI */
110
+ #define _msgpack_be_double(x) _msgpack_be64(x)
111
+ #endif
112
+
113
+ /* _msgpack_bsp32 */
114
+ #if defined(_MSC_VER)
115
+ #define _msgpack_bsp32(name, val) \
116
+ long name; \
117
+ _BitScanForward(&name, val)
118
+ #else
119
+ #define _msgpack_bsp32(name, val) \
120
+ int name = __builtin_ctz(val)
121
+ /* TODO default impl for _msgpack_bsp32 */
122
+ #endif
123
+
124
+ #ifndef HAVE_RB_INTEGER_UNPACK
125
+
126
+ #if SIZEOF_BDIGITS == 2
127
+ #define NTOHBDIGIT _msgpack_be16
128
+ #elif SIZEOF_BDIGITS == 4
129
+ #define NTOHBDIGIT _msgpack_be32
130
+ #elif SIZEOF_BDIGITS == 8
131
+ #define NTOHBDIGIT _msgpack_be64
132
+ #else
133
+ #error this size of bignum digits SIZEOF_BDIGITS not implemented
134
+ #endif
135
+
136
+ #endif
137
+
138
+ #endif
139
+
@@ -0,0 +1,59 @@
1
+ /*
2
+ * CBOR for Ruby
3
+ *
4
+ * Copyright (C) 2013 Carsten Bormann
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License").
7
+ *
8
+ * Based on:
9
+ ***********/
10
+ /*
11
+ * MessagePack for Ruby
12
+ *
13
+ * Copyright (C) 2008-2013 Sadayuki Furuhashi
14
+ *
15
+ * Licensed under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License.
17
+ * You may obtain a copy of the License at
18
+ *
19
+ * http://www.apache.org/licenses/LICENSE-2.0
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software
22
+ * distributed under the License is distributed on an "AS IS" BASIS,
23
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ * See the License for the specific language governing permissions and
25
+ * limitations under the License.
26
+ */
27
+ #ifndef MSGPACK_RUBY_SYSDEP_ENDIAN_H__
28
+ #define MSGPACK_RUBY_SYSDEP_ENDIAN_H__
29
+
30
+ /* including arpa/inet.h requires an extra dll on win32 */
31
+ #ifndef _WIN32
32
+ #include <arpa/inet.h> /* __BYTE_ORDER */
33
+ #endif
34
+
35
+ /*
36
+ * Use following command to add consitions here:
37
+ * cpp -dM `echo "#include <arpa/inet.h>" > test.c; echo test.c` | grep ENDIAN
38
+ */
39
+ #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) /* Mac OS X */
40
+ # if defined(_LITTLE_ENDIAN) \
41
+ || ( defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) \
42
+ && __BYTE_ORDER == __LITTLE_ENDIAN ) /* Linux */ \
43
+ || ( defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) \
44
+ && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ) /* Solaris */
45
+ # define __LITTLE_ENDIAN__
46
+ # elif defined(_BIG_ENDIAN) \
47
+ || (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) \
48
+ && __BYTE_ORDER == __BIG_ENDIAN) /* Linux */ \
49
+ || (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) \
50
+ && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) /* Solaris */
51
+ # define __BIG_ENDIAN__
52
+ # elif defined(_WIN32) /* Win32 */
53
+ # define __LITTLE_ENDIAN__
54
+ # endif
55
+ #endif
56
+
57
+
58
+ #endif
59
+
@@ -0,0 +1,55 @@
1
+ /*
2
+ * CBOR for Ruby
3
+ *
4
+ * Copyright (C) 2013 Carsten Bormann
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License").
7
+ *
8
+ * Based on:
9
+ ***********/
10
+ /*
11
+ * MessagePack for Ruby
12
+ *
13
+ * Copyright (C) 2008-2013 Sadayuki Furuhashi
14
+ *
15
+ * Licensed under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License.
17
+ * You may obtain a copy of the License at
18
+ *
19
+ * http://www.apache.org/licenses/LICENSE-2.0
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software
22
+ * distributed under the License is distributed on an "AS IS" BASIS,
23
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ * See the License for the specific language governing permissions and
25
+ * limitations under the License.
26
+ */
27
+ #ifndef MSGPACK_RUBY_SYSDEP_TYPES_H__
28
+ #define MSGPACK_RUBY_SYSDEP_TYPES_H__
29
+
30
+ #include <string.h>
31
+ #include <stdlib.h>
32
+
33
+ #include <stddef.h>
34
+
35
+ #if defined(_MSC_VER) && _MSC_VER < 1600
36
+ typedef __int8 int8_t;
37
+ typedef unsigned __int8 uint8_t;
38
+ typedef __int16 int16_t;
39
+ typedef unsigned __int16 uint16_t;
40
+ typedef __int32 int32_t;
41
+ typedef unsigned __int32 uint32_t;
42
+ typedef __int64 int64_t;
43
+ typedef unsigned __int64 uint64_t;
44
+
45
+ #elif defined(_MSC_VER) // && _MSC_VER >= 1600
46
+ #include <stdint.h>
47
+
48
+ #else
49
+ #include <stdint.h>
50
+ #include <stdbool.h>
51
+ #endif
52
+
53
+
54
+ #endif
55
+