sereal 0.0.2
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/ext/sereal/buffer.h +89 -0
- data/ext/sereal/decode.c +238 -0
- data/ext/sereal/decode.h +282 -0
- data/ext/sereal/encode.c +269 -0
- data/ext/sereal/encode.h +1 -0
- data/ext/sereal/extconf.rb +8 -0
- data/ext/sereal/proto.h +73 -0
- data/ext/sereal/sereal.c +12 -0
- data/ext/sereal/sereal.h +73 -0
- data/ext/sereal/snappy/csnappy.h +129 -0
- data/ext/sereal/snappy/csnappy_compress.c +659 -0
- data/ext/sereal/snappy/csnappy_decompress.c +414 -0
- data/ext/sereal/snappy/csnappy_internal.h +147 -0
- data/ext/sereal/snappy/csnappy_internal_userspace.h +301 -0
- metadata +75 -0
@@ -0,0 +1,301 @@
|
|
1
|
+
/*
|
2
|
+
Copyright 2011 Google Inc. All Rights Reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are
|
6
|
+
met:
|
7
|
+
|
8
|
+
* Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
* Redistributions in binary form must reproduce the above
|
11
|
+
copyright notice, this list of conditions and the following disclaimer
|
12
|
+
in the documentation and/or other materials provided with the
|
13
|
+
distribution.
|
14
|
+
* Neither the name of Google Inc. nor the names of its
|
15
|
+
contributors may be used to endorse or promote products derived from
|
16
|
+
this software without specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
22
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
23
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
24
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
26
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
|
30
|
+
Various stubs for the open-source version of Snappy.
|
31
|
+
|
32
|
+
File modified by
|
33
|
+
Zeev Tarantov <zeev.tarantov@gmail.com>
|
34
|
+
*/
|
35
|
+
|
36
|
+
#ifndef CSNAPPY_INTERNAL_USERSPACE_H_
|
37
|
+
#define CSNAPPY_INTERNAL_USERSPACE_H_
|
38
|
+
|
39
|
+
#if defined(_MSC_VER) && (_MSC_VER <= 1300)
|
40
|
+
typedef unsigned __int8 uint8_t;
|
41
|
+
typedef unsigned __int16 uint16_t;
|
42
|
+
typedef unsigned __int32 uint32_t;
|
43
|
+
typedef unsigned __int64 uint64_t;
|
44
|
+
#else
|
45
|
+
#include <stdint.h>
|
46
|
+
#endif
|
47
|
+
|
48
|
+
#ifdef _GNU_SOURCE
|
49
|
+
#define min(x, y) (__extension__ ({ \
|
50
|
+
typeof(x) _min1 = (x); \
|
51
|
+
typeof(y) _min2 = (y); \
|
52
|
+
(void) (&_min1 == &_min2); \
|
53
|
+
_min1 < _min2 ? _min1 : _min2; }))
|
54
|
+
#else
|
55
|
+
#define min(x, y) (((x) < (y)) ? (x) : (y))
|
56
|
+
#endif
|
57
|
+
|
58
|
+
/* Static prediction hints. */
|
59
|
+
#ifndef __GNUC__
|
60
|
+
#define __builtin_expect(a,b) a
|
61
|
+
#endif
|
62
|
+
#define likely(x) __builtin_expect(!!(x), 1)
|
63
|
+
#define unlikely(x) __builtin_expect(!!(x), 0)
|
64
|
+
|
65
|
+
|
66
|
+
#ifdef DEBUG
|
67
|
+
#include <assert.h>
|
68
|
+
#define DCHECK(cond) assert(cond)
|
69
|
+
#else
|
70
|
+
#define DCHECK(cond)
|
71
|
+
#endif
|
72
|
+
|
73
|
+
/*
|
74
|
+
Uses code from http://code.google.com/p/exfat/source/browse/trunk/libexfat/byteorder.h
|
75
|
+
with 3-clause BSD license instead of GPL, with permission from:
|
76
|
+
Andrew Nayenko
|
77
|
+
Albert Lee
|
78
|
+
*/
|
79
|
+
#if defined(_MSC_VER)
|
80
|
+
|
81
|
+
#include <stdlib.h>
|
82
|
+
#define bswap_16(x) _byteswap_ushort(x)
|
83
|
+
#define bswap_32(x) _byteswap_ulong(x)
|
84
|
+
#define bswap_64(x) _byteswap_uint64(x)
|
85
|
+
|
86
|
+
#elif defined(__GLIBC__) || defined(__ANDROID__) || defined(__CYGWIN__)
|
87
|
+
|
88
|
+
#include <endian.h>
|
89
|
+
#include <byteswap.h>
|
90
|
+
|
91
|
+
#elif defined(__APPLE__)
|
92
|
+
|
93
|
+
#include <machine/endian.h>
|
94
|
+
#include <libkern/OSByteOrder.h>
|
95
|
+
#define bswap_16(x) OSSwapInt16(x)
|
96
|
+
#define bswap_32(x) OSSwapInt32(x)
|
97
|
+
#define bswap_64(x) OSSwapInt64(x)
|
98
|
+
#define __BYTE_ORDER BYTE_ORDER
|
99
|
+
#define __LITTLE_ENDIAN LITTLE_ENDIAN
|
100
|
+
#define __BIG_ENDIAN BIG_ENDIAN
|
101
|
+
|
102
|
+
#elif defined(__FreeBSD__) || defined(__DragonFlyBSD__) || defined(__NetBSD__)
|
103
|
+
|
104
|
+
#include <sys/endian.h>
|
105
|
+
#define bswap_16(x) bswap16(x)
|
106
|
+
#define bswap_32(x) bswap32(x)
|
107
|
+
#define bswap_64(x) bswap64(x)
|
108
|
+
#define __BYTE_ORDER _BYTE_ORDER
|
109
|
+
#define __LITTLE_ENDIAN _LITTLE_ENDIAN
|
110
|
+
#define __BIG_ENDIAN _BIG_ENDIAN
|
111
|
+
|
112
|
+
#elif defined(__OpenBSD__)
|
113
|
+
|
114
|
+
#include <machine/endian.h>
|
115
|
+
#define bswap_16(x) swap16(x)
|
116
|
+
#define bswap_32(x) swap32(x)
|
117
|
+
#define bswap_64(x) swap64(x)
|
118
|
+
#define __BYTE_ORDER _BYTE_ORDER
|
119
|
+
#define __LITTLE_ENDIAN _LITTLE_ENDIAN
|
120
|
+
#define __BIG_ENDIAN _BIG_ENDIAN
|
121
|
+
|
122
|
+
#elif defined(__sun)
|
123
|
+
|
124
|
+
#include <sys/byteorder.h>
|
125
|
+
#define bswap_16(x) BSWAP_16(x)
|
126
|
+
#define bswap_32(x) BSWAP_32(x)
|
127
|
+
#define bswap_64(x) BSWAP_64(x)
|
128
|
+
#define __LITTLE_ENDIAN 1234
|
129
|
+
#define __BIG_ENDIAN 4321
|
130
|
+
#ifdef _LITTLE_ENDIAN
|
131
|
+
#define __BYTE_ORDER __LITTLE_ENDIAN
|
132
|
+
#else
|
133
|
+
#define __BYTE_ORDER __BIG_ENDIAN
|
134
|
+
#endif
|
135
|
+
|
136
|
+
#endif
|
137
|
+
|
138
|
+
|
139
|
+
/* Potentially unaligned loads and stores. */
|
140
|
+
|
141
|
+
#if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__)
|
142
|
+
|
143
|
+
#define UNALIGNED_LOAD16(_p) (*(const uint16_t*)(_p))
|
144
|
+
#define UNALIGNED_LOAD32(_p) (*(const uint32_t*)(_p))
|
145
|
+
#define UNALIGNED_LOAD64(_p) (*(const uint64_t*)(_p))
|
146
|
+
|
147
|
+
#define UNALIGNED_STORE16(_p, _val) (*(uint16_t*)(_p) = (_val))
|
148
|
+
#define UNALIGNED_STORE32(_p, _val) (*(uint32_t*)(_p) = (_val))
|
149
|
+
#define UNALIGNED_STORE64(_p, _val) (*(uint64_t*)(_p) = (_val))
|
150
|
+
|
151
|
+
#elif defined(__arm__) && \
|
152
|
+
!defined(__ARM_ARCH_4__) && \
|
153
|
+
!defined(__ARM_ARCH_4T__) && /* http://wiki.debian.org/ArmEabiPort#Choice_of_minimum_CPU */ \
|
154
|
+
!defined(__MARM_ARMV4__) && \
|
155
|
+
!defined(_ARMV4I_) && \
|
156
|
+
!defined(__ARM_ARCH_5__) && \
|
157
|
+
!defined(__ARM_ARCH_5T__) && \
|
158
|
+
!defined(__ARM_ARCH_5E__) && \
|
159
|
+
!defined(__ARM_ARCH_5TE__) && \
|
160
|
+
!defined(__ARM_ARCH_5TEJ__) && \
|
161
|
+
!defined(__MARM_ARMV5__)
|
162
|
+
|
163
|
+
#define UNALIGNED_LOAD16(_p) (*(const uint16_t*)(_p))
|
164
|
+
#define UNALIGNED_LOAD32(_p) (*(const uint32_t*)(_p))
|
165
|
+
#define UNALIGNED_STORE16(_p, _val) (*(uint16_t*)(_p) = (_val))
|
166
|
+
#define UNALIGNED_STORE32(_p, _val) (*(uint32_t*)(_p) = (_val))
|
167
|
+
|
168
|
+
#pragma pack(1)
|
169
|
+
struct una_u64 { uint64_t x; };
|
170
|
+
#pragma pack()
|
171
|
+
|
172
|
+
static inline uint64_t UNALIGNED_LOAD64(const void *p)
|
173
|
+
{
|
174
|
+
const struct una_u64 *ptr = (const struct una_u64 *)p;
|
175
|
+
return ptr->x;
|
176
|
+
}
|
177
|
+
|
178
|
+
static inline void UNALIGNED_STORE64(void *p, uint64_t v)
|
179
|
+
{
|
180
|
+
struct una_u64 *ptr = (struct una_u64 *)p;
|
181
|
+
ptr->x = v;
|
182
|
+
}
|
183
|
+
|
184
|
+
#else /* !(x86 || powerpc) && !(arm && !(old arm architectures)) */
|
185
|
+
|
186
|
+
#pragma pack(1)
|
187
|
+
struct una_u16 { uint16_t x; };
|
188
|
+
struct una_u32 { uint32_t x; };
|
189
|
+
struct una_u64 { uint64_t x; };
|
190
|
+
#pragma pack()
|
191
|
+
|
192
|
+
static inline uint16_t UNALIGNED_LOAD16(const void *p)
|
193
|
+
{
|
194
|
+
const struct una_u16 *ptr = (const struct una_u16 *)p;
|
195
|
+
return ptr->x;
|
196
|
+
}
|
197
|
+
|
198
|
+
static inline uint32_t UNALIGNED_LOAD32(const void *p)
|
199
|
+
{
|
200
|
+
const struct una_u32 *ptr = (const struct una_u32 *)p;
|
201
|
+
return ptr->x;
|
202
|
+
}
|
203
|
+
|
204
|
+
static inline uint64_t UNALIGNED_LOAD64(const void *p)
|
205
|
+
{
|
206
|
+
const struct una_u64 *ptr = (const struct una_u64 *)p;
|
207
|
+
return ptr->x;
|
208
|
+
}
|
209
|
+
|
210
|
+
static inline void UNALIGNED_STORE16(void *p, uint16_t v)
|
211
|
+
{
|
212
|
+
struct una_u16 *ptr = (struct una_u16 *)p;
|
213
|
+
ptr->x = v;
|
214
|
+
}
|
215
|
+
|
216
|
+
static inline void UNALIGNED_STORE32(void *p, uint32_t v)
|
217
|
+
{
|
218
|
+
struct una_u32 *ptr = (struct una_u32 *)p;
|
219
|
+
ptr->x = v;
|
220
|
+
}
|
221
|
+
|
222
|
+
static inline void UNALIGNED_STORE64(void *p, uint64_t v)
|
223
|
+
{
|
224
|
+
struct una_u64 *ptr = (struct una_u64 *)p;
|
225
|
+
ptr->x = v;
|
226
|
+
}
|
227
|
+
|
228
|
+
#endif /* !(x86 || powerpc) && !(arm && !armv5 && !armv6) */
|
229
|
+
|
230
|
+
|
231
|
+
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
232
|
+
#define get_unaligned_le32(p) UNALIGNED_LOAD32(p)
|
233
|
+
#define put_unaligned_le16(v, p) UNALIGNED_STORE16(p, v)
|
234
|
+
#elif __BYTE_ORDER == __BIG_ENDIAN
|
235
|
+
static inline uint32_t get_unaligned_le32(const void *p)
|
236
|
+
{
|
237
|
+
return bswap_32(UNALIGNED_LOAD32(p));
|
238
|
+
}
|
239
|
+
static inline void put_unaligned_le16(uint16_t val, void *p)
|
240
|
+
{
|
241
|
+
UNALIGNED_STORE16(p, bswap_16(val));
|
242
|
+
}
|
243
|
+
#else
|
244
|
+
static inline uint32_t get_unaligned_le32(const void *p)
|
245
|
+
{
|
246
|
+
const uint8_t *b = (const uint8_t *)p;
|
247
|
+
return b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24);
|
248
|
+
}
|
249
|
+
static inline void put_unaligned_le16(uint16_t val, void *p)
|
250
|
+
{
|
251
|
+
uint8_t *b = (uint8_t *)p;
|
252
|
+
b[0] = val & 255;
|
253
|
+
b[1] = val >> 8;
|
254
|
+
}
|
255
|
+
#endif
|
256
|
+
|
257
|
+
|
258
|
+
#if defined(HAVE_BUILTIN_CTZ)
|
259
|
+
|
260
|
+
static inline int FindLSBSetNonZero(uint32_t n)
|
261
|
+
{
|
262
|
+
return __builtin_ctz(n);
|
263
|
+
}
|
264
|
+
|
265
|
+
static inline int FindLSBSetNonZero64(uint64_t n)
|
266
|
+
{
|
267
|
+
return __builtin_ctzll(n);
|
268
|
+
}
|
269
|
+
|
270
|
+
#else /* Portable versions. */
|
271
|
+
|
272
|
+
static inline int FindLSBSetNonZero(uint32_t n)
|
273
|
+
{
|
274
|
+
int rc = 31, i, shift;
|
275
|
+
uint32_t x;
|
276
|
+
for (i = 4, shift = 1 << 4; i >= 0; --i) {
|
277
|
+
x = n << shift;
|
278
|
+
if (x != 0) {
|
279
|
+
n = x;
|
280
|
+
rc -= shift;
|
281
|
+
}
|
282
|
+
shift >>= 1;
|
283
|
+
}
|
284
|
+
return rc;
|
285
|
+
}
|
286
|
+
|
287
|
+
/* FindLSBSetNonZero64() is defined in terms of FindLSBSetNonZero(). */
|
288
|
+
static inline int FindLSBSetNonZero64(uint64_t n)
|
289
|
+
{
|
290
|
+
const uint32_t bottombits = (uint32_t)n;
|
291
|
+
if (bottombits == 0) {
|
292
|
+
/* Bottom bits are zero, so scan in top bits */
|
293
|
+
return 32 + FindLSBSetNonZero((uint32_t)(n >> 32));
|
294
|
+
} else {
|
295
|
+
return FindLSBSetNonZero(bottombits);
|
296
|
+
}
|
297
|
+
}
|
298
|
+
|
299
|
+
#endif /* End portable versions. */
|
300
|
+
|
301
|
+
#endif /* CSNAPPY_INTERNAL_USERSPACE_H_ */
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sereal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Borislav Nikolov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake-compiler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Sereal encoder/decoder (https://github.com/Sereal/Sereal)
|
31
|
+
email: jack@sofialondonmoskva.com
|
32
|
+
executables: []
|
33
|
+
extensions:
|
34
|
+
- ext/sereal/extconf.rb
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- ext/sereal/snappy/csnappy_compress.c
|
38
|
+
- ext/sereal/snappy/csnappy_decompress.c
|
39
|
+
- ext/sereal/decode.c
|
40
|
+
- ext/sereal/encode.c
|
41
|
+
- ext/sereal/sereal.c
|
42
|
+
- ext/sereal/buffer.h
|
43
|
+
- ext/sereal/snappy/csnappy_internal_userspace.h
|
44
|
+
- ext/sereal/snappy/csnappy.h
|
45
|
+
- ext/sereal/snappy/csnappy_internal.h
|
46
|
+
- ext/sereal/sereal.h
|
47
|
+
- ext/sereal/encode.h
|
48
|
+
- ext/sereal/decode.h
|
49
|
+
- ext/sereal/proto.h
|
50
|
+
- ext/sereal/extconf.rb
|
51
|
+
homepage: https://github.com/Sereal/Sereal
|
52
|
+
licenses: []
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.8.23
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Sereal encoder/decoder
|
75
|
+
test_files: []
|