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.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/.gitlab-ci.yml +44 -0
- data/.travis.yml +24 -0
- data/CHANGELOG.md +30 -0
- data/ChangeLog +106 -0
- data/Gemfile +11 -0
- data/README.rdoc +191 -0
- data/Rakefile +97 -0
- data/ci/test.rb +31 -0
- data/doclib/cbor/buffer.rb +193 -0
- data/doclib/cbor/core_ext.rb +133 -0
- data/doclib/cbor/error.rb +14 -0
- data/doclib/cbor/packer.rb +133 -0
- data/doclib/cbor/simple.rb +15 -0
- data/doclib/cbor/tagged.rb +16 -0
- data/doclib/cbor/unpacker.rb +138 -0
- data/doclib/cbor.rb +80 -0
- data/ext/cbor/buffer.c +693 -0
- data/ext/cbor/buffer.h +484 -0
- data/ext/cbor/buffer_class.c +561 -0
- data/ext/cbor/buffer_class.h +41 -0
- data/ext/cbor/cbor.h +69 -0
- data/ext/cbor/compat.h +147 -0
- data/ext/cbor/core_ext.c +199 -0
- data/ext/cbor/core_ext.h +35 -0
- data/ext/cbor/extconf.rb +29 -0
- data/ext/cbor/packer.c +169 -0
- data/ext/cbor/packer.h +370 -0
- data/ext/cbor/packer_class.c +345 -0
- data/ext/cbor/packer_class.h +40 -0
- data/ext/cbor/rbinit.c +57 -0
- data/ext/cbor/renamer.h +56 -0
- data/ext/cbor/rmem.c +103 -0
- data/ext/cbor/rmem.h +118 -0
- data/ext/cbor/sysdep.h +139 -0
- data/ext/cbor/sysdep_endian.h +59 -0
- data/ext/cbor/sysdep_types.h +55 -0
- data/ext/cbor/unpacker.c +787 -0
- data/ext/cbor/unpacker.h +135 -0
- data/ext/cbor/unpacker_class.c +483 -0
- data/ext/cbor/unpacker_class.h +39 -0
- data/gitlab-cbor.gemspec +27 -0
- data/lib/cbor/version.rb +3 -0
- data/lib/cbor.rb +6 -0
- data/spec/buffer_io_spec.rb +260 -0
- data/spec/buffer_spec.rb +576 -0
- data/spec/cases.cbor +0 -0
- data/spec/cases.cbor_stream +0 -0
- data/spec/cases.json +1 -0
- data/spec/cases.msg +0 -0
- data/spec/cases_compact.msg +0 -0
- data/spec/cases_spec.rb +39 -0
- data/spec/format_spec.rb +603 -0
- data/spec/packer_spec.rb +127 -0
- data/spec/random_compat.rb +24 -0
- data/spec/spec_helper.rb +68 -0
- data/spec/unpacker_spec.rb +260 -0
- metadata +189 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
module CBOR
|
|
2
|
+
|
|
3
|
+
class Buffer
|
|
4
|
+
#
|
|
5
|
+
# Creates a CBOR::Buffer instance.
|
|
6
|
+
#
|
|
7
|
+
# @overload initialize(options={})
|
|
8
|
+
# @param options [Hash]
|
|
9
|
+
#
|
|
10
|
+
# @overload initialize(io, options={})
|
|
11
|
+
# @param io [IO]
|
|
12
|
+
# @param options [Hash]
|
|
13
|
+
# This buffer writes written data into the IO when it is filled.
|
|
14
|
+
# This buffer reads data from the IO when it is empty.
|
|
15
|
+
#
|
|
16
|
+
# _io_ must respond to readpartial(length, [,string]) or read(string) method and
|
|
17
|
+
# write(string) or append(string) method.
|
|
18
|
+
#
|
|
19
|
+
# Supported options:
|
|
20
|
+
#
|
|
21
|
+
# * *:io_buffer_size* buffer size to read data from the internal IO. (default: 32768)
|
|
22
|
+
# * *:read_reference_threshold* the threshold size to enable zero-copy deserialize optimization. Read strings longer than this threshold will refer the original string instead of copying it. (default: 256) (supported in MRI only)
|
|
23
|
+
# * *:write_reference_threshold* the threshold size to enable zero-copy serialize optimization. The buffer refers written strings longer than this threshold instead of copying it. (default: 524288) (supported in MRI only)
|
|
24
|
+
#
|
|
25
|
+
def initialize(*args)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
#
|
|
29
|
+
# Makes the buffer empty
|
|
30
|
+
#
|
|
31
|
+
# @return nil
|
|
32
|
+
#
|
|
33
|
+
def clear
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
#
|
|
37
|
+
# Returns byte size of the buffer.
|
|
38
|
+
#
|
|
39
|
+
# @return nil
|
|
40
|
+
#
|
|
41
|
+
def size
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
#
|
|
45
|
+
# Returns _true_ if the buffer is empty.
|
|
46
|
+
# This method is slightly faster than _size_.
|
|
47
|
+
#
|
|
48
|
+
# @return [Boolean]
|
|
49
|
+
#
|
|
50
|
+
def empty?
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
#
|
|
54
|
+
# Appends the given data to the buffer.
|
|
55
|
+
#
|
|
56
|
+
# @param data [String]
|
|
57
|
+
# @return [Integer] byte size written
|
|
58
|
+
#
|
|
59
|
+
def write(data)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
#
|
|
63
|
+
# Appends the given data to the buffer.
|
|
64
|
+
#
|
|
65
|
+
# @param data [String]
|
|
66
|
+
# @return [Buffer] self
|
|
67
|
+
#
|
|
68
|
+
def <<(data)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
#
|
|
72
|
+
# Consumes _n_ bytes from the head of the buffer and returns consumed data.
|
|
73
|
+
# If the size of the buffer is less than _n_, it reads all of data in the buffer.
|
|
74
|
+
#
|
|
75
|
+
# If _n_ is 0, it does nothing and returns an empty string.
|
|
76
|
+
# If the optional _buffer_ argument is given, the content of the string will be replaced with the consumed data.
|
|
77
|
+
#
|
|
78
|
+
# @overload read
|
|
79
|
+
#
|
|
80
|
+
# @overload read(n)
|
|
81
|
+
# @param n [Integer] bytes to read
|
|
82
|
+
#
|
|
83
|
+
# @overload read(n, buffer)
|
|
84
|
+
# @param n [Integer] bytes to read
|
|
85
|
+
# @param buffer [String] buffer to read into
|
|
86
|
+
#
|
|
87
|
+
# @return [String]
|
|
88
|
+
#
|
|
89
|
+
def read(n)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
#
|
|
93
|
+
# Consumes _n_ bytes from the head of the buffer and returns consumed data.
|
|
94
|
+
# If the size of the buffer is less than _n_, it does nothing and raises EOFError.
|
|
95
|
+
#
|
|
96
|
+
# If _n_ is 0, it does nothing and returns an empty string.
|
|
97
|
+
# If the optional _buffer_ argument is given, the content of the string will be replaced with the consumed data.
|
|
98
|
+
#
|
|
99
|
+
# @overload read_all
|
|
100
|
+
#
|
|
101
|
+
# @overload read_all(n)
|
|
102
|
+
# @param n [Integer] bytes to read
|
|
103
|
+
#
|
|
104
|
+
# @overload read_all(n, buffer)
|
|
105
|
+
# @param n [Integer] bytes to read
|
|
106
|
+
# @param buffer [String] buffer to read into
|
|
107
|
+
#
|
|
108
|
+
# @return [String]
|
|
109
|
+
#
|
|
110
|
+
def read_all(n, buffer=nil)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
#
|
|
114
|
+
# Consumes _n_ bytes from the head of the buffer.
|
|
115
|
+
# If the size of the buffer is less than _n_, it skips all of data in the buffer and returns integer less than _n_.
|
|
116
|
+
#
|
|
117
|
+
# If _n_ is 0, it does nothing and returns _0_.
|
|
118
|
+
#
|
|
119
|
+
# @param n [Integer] byte size to skip
|
|
120
|
+
# @return [Integer] byte size actually skipped
|
|
121
|
+
#
|
|
122
|
+
def skip(n)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
#
|
|
126
|
+
# Consumes _n_ bytes from the head of the buffer.
|
|
127
|
+
# If the size of the buffer is less than _n_, it does nothing and raises EOFError.
|
|
128
|
+
# If _n_ is 0, it does nothing.
|
|
129
|
+
#
|
|
130
|
+
# @param n [Integer] byte size to skip
|
|
131
|
+
# @return [Buffer] self
|
|
132
|
+
#
|
|
133
|
+
def skip_all(n)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
#
|
|
137
|
+
# Returns all data in the buffer as a string.
|
|
138
|
+
# Destructive update to the returned string does NOT effect the buffer.
|
|
139
|
+
#
|
|
140
|
+
# @return [String]
|
|
141
|
+
#
|
|
142
|
+
def to_str
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
#
|
|
146
|
+
# Returns content of the buffer as an array of strings.
|
|
147
|
+
#
|
|
148
|
+
# This method is sometimes faster than to_s because the internal
|
|
149
|
+
# structure of the buffer is a queue of buffer chunks.
|
|
150
|
+
#
|
|
151
|
+
# @return [Array] array of strings
|
|
152
|
+
#
|
|
153
|
+
def to_a
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
#
|
|
157
|
+
# Internal io
|
|
158
|
+
#
|
|
159
|
+
# @return IO
|
|
160
|
+
#
|
|
161
|
+
attr_reader :io
|
|
162
|
+
|
|
163
|
+
#
|
|
164
|
+
# Flushes data in the internal buffer to the internal IO.
|
|
165
|
+
# If internal IO is not set, it does nothing.
|
|
166
|
+
#
|
|
167
|
+
# @return [Buffer] self
|
|
168
|
+
#
|
|
169
|
+
def flush
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
#
|
|
173
|
+
# Closes internal IO if its set.
|
|
174
|
+
# If internal IO is not set, it does nothing
|
|
175
|
+
#
|
|
176
|
+
# @return nil
|
|
177
|
+
#
|
|
178
|
+
def close
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
#
|
|
182
|
+
# Writes all of data in the internal buffer into the given IO.
|
|
183
|
+
# This method consumes and removes data from the internal buffer.
|
|
184
|
+
# _io_ must respond to write(data) method.
|
|
185
|
+
#
|
|
186
|
+
# @param io [IO]
|
|
187
|
+
# @return [Integer] byte size of written data
|
|
188
|
+
#
|
|
189
|
+
def write_to(io)
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
end
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
|
|
2
|
+
class NilClass
|
|
3
|
+
#
|
|
4
|
+
# Same as CBOR.encode(self[, io]).
|
|
5
|
+
#
|
|
6
|
+
# @return [String] serialized data
|
|
7
|
+
#
|
|
8
|
+
def to_cbor(io=nil)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class TrueClass
|
|
13
|
+
#
|
|
14
|
+
# Same as CBOR.encode(self[, io]).
|
|
15
|
+
#
|
|
16
|
+
# @return [String] serialized data
|
|
17
|
+
#
|
|
18
|
+
def to_cbor(io=nil)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class FalseClass
|
|
23
|
+
#
|
|
24
|
+
# Same as CBOR.encode(self[, io]).
|
|
25
|
+
#
|
|
26
|
+
# @return [String] serialized data
|
|
27
|
+
#
|
|
28
|
+
def to_cbor(io=nil)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class Fixnum < Integer
|
|
33
|
+
#
|
|
34
|
+
# Same as CBOR.encode(self[, io]).
|
|
35
|
+
#
|
|
36
|
+
# @return [String] serialized data
|
|
37
|
+
#
|
|
38
|
+
def to_cbor(io=nil)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class Bignum < Integer
|
|
43
|
+
#
|
|
44
|
+
# Same as CBOR.encode(self[, io]).
|
|
45
|
+
#
|
|
46
|
+
# @return [String] serialized data
|
|
47
|
+
#
|
|
48
|
+
def to_cbor(io=nil)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class Float < Numeric
|
|
53
|
+
#
|
|
54
|
+
# Same as CBOR.encode(self[, io]).
|
|
55
|
+
#
|
|
56
|
+
# @return [String] serialized data
|
|
57
|
+
#
|
|
58
|
+
def to_cbor(io=nil)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
class String
|
|
63
|
+
#
|
|
64
|
+
# Same as CBOR.encode(self[, io]).
|
|
65
|
+
#
|
|
66
|
+
# @return [String] serialized data
|
|
67
|
+
#
|
|
68
|
+
def to_cbor(io=nil)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
class Array
|
|
73
|
+
#
|
|
74
|
+
# Same as CBOR.encode(self[, io]).
|
|
75
|
+
#
|
|
76
|
+
# @return [String] serialized data
|
|
77
|
+
#
|
|
78
|
+
def to_cbor(io=nil)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
class Hash
|
|
83
|
+
#
|
|
84
|
+
# Same as CBOR.encode(self[, io]).
|
|
85
|
+
#
|
|
86
|
+
# @return [String] serialized data
|
|
87
|
+
#
|
|
88
|
+
def to_cbor(io=nil)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
class Time
|
|
93
|
+
#
|
|
94
|
+
# Same as CBOR.encode(self[, io]).
|
|
95
|
+
#
|
|
96
|
+
# @return [String] serialized data
|
|
97
|
+
#
|
|
98
|
+
def to_cbor(io=nil)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class Regexp
|
|
104
|
+
#
|
|
105
|
+
# Same as CBOR.encode(self[, io]).
|
|
106
|
+
#
|
|
107
|
+
# @return [String] serialized data
|
|
108
|
+
#
|
|
109
|
+
def to_cbor(io=nil)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
class URI
|
|
114
|
+
#
|
|
115
|
+
# Same as CBOR.encode(self[, io]). This method is only defined if
|
|
116
|
+
# the class URI was defined when the CBOR extension was loaded, so
|
|
117
|
+
# +require "uri"+ before +require "cbor"+ if you need this.
|
|
118
|
+
#
|
|
119
|
+
# @return [String] serialized data
|
|
120
|
+
#
|
|
121
|
+
def to_cbor(io=nil)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
class Symbol
|
|
126
|
+
#
|
|
127
|
+
# Same as CBOR.encode(self[, io]).
|
|
128
|
+
#
|
|
129
|
+
# @return [String] serialized data
|
|
130
|
+
#
|
|
131
|
+
def to_cbor(io=nil)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
module CBOR
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# CBOR::Packer is an interface to serialize objects into an internal buffer,
|
|
5
|
+
# which is a CBOR::Buffer.
|
|
6
|
+
#
|
|
7
|
+
class Packer
|
|
8
|
+
#
|
|
9
|
+
# Creates a CBOR::Packer instance.
|
|
10
|
+
# See Buffer#initialize for supported options.
|
|
11
|
+
#
|
|
12
|
+
# @overload initialize(options={})
|
|
13
|
+
# @param options [Hash]
|
|
14
|
+
#
|
|
15
|
+
# @overload initialize(io, options={})
|
|
16
|
+
# @param io [IO]
|
|
17
|
+
# @param options [Hash]
|
|
18
|
+
# This packer writes serialzied objects into the IO when the internal buffer is filled.
|
|
19
|
+
# _io_ must respond to write(string) or append(string) method.
|
|
20
|
+
#
|
|
21
|
+
def initialize(*args)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
#
|
|
25
|
+
# Internal buffer
|
|
26
|
+
#
|
|
27
|
+
# @return CBOR::Buffer
|
|
28
|
+
#
|
|
29
|
+
attr_reader :buffer
|
|
30
|
+
|
|
31
|
+
#
|
|
32
|
+
# Serializes an object into internal buffer.
|
|
33
|
+
#
|
|
34
|
+
# If it could not serialize the object, it raises
|
|
35
|
+
# NoMethodError: undefined method `to_cbor' for #<the_object>.
|
|
36
|
+
#
|
|
37
|
+
# @param obj [Object] object to serialize
|
|
38
|
+
# @return [Packer] self
|
|
39
|
+
#
|
|
40
|
+
def write(obj)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
alias pack write
|
|
44
|
+
|
|
45
|
+
#
|
|
46
|
+
# Serializes a nil object. Same as write(nil).
|
|
47
|
+
#
|
|
48
|
+
def write_nil
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
#
|
|
52
|
+
# Write a header of an array whose size is _n_.
|
|
53
|
+
# For example, write_array_header(1).write(true) is same as write([ true ]).
|
|
54
|
+
#
|
|
55
|
+
# @return [Packer] self
|
|
56
|
+
#
|
|
57
|
+
def write_array_header(n)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
#
|
|
61
|
+
# Write a header of an map whose size is _n_.
|
|
62
|
+
# For example, write_map_header(1).write('key').write(true) is same as write('key'=>true).
|
|
63
|
+
#
|
|
64
|
+
# @return [Packer] self
|
|
65
|
+
#
|
|
66
|
+
def write_map_header(n)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
#
|
|
70
|
+
# Flushes data in the internal buffer to the internal IO. Same as _buffer.flush.
|
|
71
|
+
# If internal IO is not set, it does nothing.
|
|
72
|
+
#
|
|
73
|
+
# @return [Packer] self
|
|
74
|
+
#
|
|
75
|
+
def flush
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
#
|
|
79
|
+
# Makes the internal buffer empty. Same as _buffer.clear_.
|
|
80
|
+
#
|
|
81
|
+
# @return nil
|
|
82
|
+
#
|
|
83
|
+
def clear
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
#
|
|
87
|
+
# Returns size of the internal buffer. Same as buffer.size.
|
|
88
|
+
#
|
|
89
|
+
# @return [Integer]
|
|
90
|
+
#
|
|
91
|
+
def size
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
#
|
|
95
|
+
# Returns _true_ if the internal buffer is empty. Same as buffer.empty?.
|
|
96
|
+
# This method is slightly faster than _size_.
|
|
97
|
+
#
|
|
98
|
+
# @return [Boolean]
|
|
99
|
+
#
|
|
100
|
+
def empty?
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
#
|
|
104
|
+
# Returns all data in the buffer as a string. Same as buffer.to_str.
|
|
105
|
+
#
|
|
106
|
+
# @return [String]
|
|
107
|
+
#
|
|
108
|
+
def to_str
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
alias to_s to_str
|
|
112
|
+
|
|
113
|
+
#
|
|
114
|
+
# Returns content of the internal buffer as an array of strings. Same as buffer.to_a.
|
|
115
|
+
# This method is faster than _to_str_.
|
|
116
|
+
#
|
|
117
|
+
# @return [Array] array of strings
|
|
118
|
+
#
|
|
119
|
+
def to_a
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
#
|
|
123
|
+
# Writes all of data in the internal buffer into the given IO. Same as buffer.write_to(io).
|
|
124
|
+
# This method consumes and removes data from the internal buffer.
|
|
125
|
+
# _io_ must respond to write(data) method.
|
|
126
|
+
#
|
|
127
|
+
# @param io [IO]
|
|
128
|
+
# @return [Integer] byte size of written data
|
|
129
|
+
#
|
|
130
|
+
def write_to(io)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module CBOR
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# CBOR::Simple is used to carry around simple values that don't map
|
|
5
|
+
# into Ruby classes (false, true, nil are the ones that do).
|
|
6
|
+
class Simple
|
|
7
|
+
|
|
8
|
+
# @param value [Integer] The integer number of the simple value
|
|
9
|
+
def initialize(value)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
attr_reader :value
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module CBOR
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# CBOR::Tagged is used to carry around tagged values that don't map
|
|
5
|
+
# into Ruby classes (false, true, nil are the ones that do).
|
|
6
|
+
class Tagged
|
|
7
|
+
|
|
8
|
+
# @param tag [Integer] The integer number of the tag
|
|
9
|
+
# @param value [Object] The value that is being tagged
|
|
10
|
+
def initialize(tag, value)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
attr_reader :tag, :value
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
module CBOR
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# CBOR::Unpacker is an interface to deserialize objects from an internal buffer,
|
|
5
|
+
# which is a CBOR::Buffer.
|
|
6
|
+
#
|
|
7
|
+
class Unpacker
|
|
8
|
+
#
|
|
9
|
+
# Creates a CBOR::Unpacker instance.
|
|
10
|
+
#
|
|
11
|
+
# @overload initialize(options={})
|
|
12
|
+
# @param options [Hash]
|
|
13
|
+
#
|
|
14
|
+
# @overload initialize(io, options={})
|
|
15
|
+
# @param io [IO]
|
|
16
|
+
# @param options [Hash]
|
|
17
|
+
# This unpacker reads data from the _io_ to fill the internal buffer.
|
|
18
|
+
# _io_ must respond to readpartial(length [,string]) or read(length [,string]) method.
|
|
19
|
+
#
|
|
20
|
+
# See Buffer#initialize for supported options.
|
|
21
|
+
#
|
|
22
|
+
def initialize(*args)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
#
|
|
26
|
+
# Internal buffer
|
|
27
|
+
#
|
|
28
|
+
# @return [CBOR::Buffer]
|
|
29
|
+
#
|
|
30
|
+
attr_reader :buffer
|
|
31
|
+
|
|
32
|
+
#
|
|
33
|
+
# Deserializes an object from internal buffer and returns it.
|
|
34
|
+
#
|
|
35
|
+
# If there're not enough buffer, this method raises EOFError.
|
|
36
|
+
# If data format is invalid, this method raises CBOR::MalformedFormatError.
|
|
37
|
+
# If the stack is too deep, this method raises CBOR::StackError.
|
|
38
|
+
#
|
|
39
|
+
# @return [Object] deserialized object
|
|
40
|
+
#
|
|
41
|
+
def read
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
alias unpack read
|
|
45
|
+
|
|
46
|
+
#
|
|
47
|
+
# Deserializes an object and ignores it. This method is faster than _read_.
|
|
48
|
+
#
|
|
49
|
+
# This method could raise same errors with _read_.
|
|
50
|
+
#
|
|
51
|
+
# @return nil
|
|
52
|
+
#
|
|
53
|
+
def skip
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
#
|
|
57
|
+
# Deserializes a nil value if it exists and returns _true_.
|
|
58
|
+
# Otherwise, if a byte exists but the byte doesn't represent nil value,
|
|
59
|
+
# returns _false_.
|
|
60
|
+
#
|
|
61
|
+
# If there're not enough buffer, this method raises EOFError.
|
|
62
|
+
#
|
|
63
|
+
# @return [Boolean]
|
|
64
|
+
#
|
|
65
|
+
def skip_nil
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
#
|
|
69
|
+
# Read a header of an array and returns its size.
|
|
70
|
+
# It converts a serialized array into a stream of elements.
|
|
71
|
+
#
|
|
72
|
+
# If the serialized object is not an array, it raises CBOR::TypeError.
|
|
73
|
+
# If there're not enough buffer, this method raises EOFError.
|
|
74
|
+
#
|
|
75
|
+
# @return [Integer] size of the array
|
|
76
|
+
#
|
|
77
|
+
def read_array_header
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
#
|
|
81
|
+
# Reads a header of an map and returns its size.
|
|
82
|
+
# It converts a serialized map into a stream of key-value pairs.
|
|
83
|
+
#
|
|
84
|
+
# If the serialized object is not a map, it raises CBOR::TypeError.
|
|
85
|
+
# If there're not enough buffer, this method raises EOFError.
|
|
86
|
+
#
|
|
87
|
+
# @return [Integer] size of the map
|
|
88
|
+
#
|
|
89
|
+
def read_map_header
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
#
|
|
93
|
+
# Appends data into the internal buffer.
|
|
94
|
+
# This method calls buffer.append(data).
|
|
95
|
+
#
|
|
96
|
+
# @param data [String]
|
|
97
|
+
# @return [Unpacker] self
|
|
98
|
+
#
|
|
99
|
+
def feed(data)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
#
|
|
103
|
+
# Repeats to deserialize objects.
|
|
104
|
+
#
|
|
105
|
+
# It repeats until the internal buffer does not include any complete objects.
|
|
106
|
+
#
|
|
107
|
+
# If the an IO is set, it repeats to read data from the IO when the buffer
|
|
108
|
+
# becomes empty until the IO raises EOFError.
|
|
109
|
+
#
|
|
110
|
+
# This method could raise same errors with _read_ excepting EOFError.
|
|
111
|
+
#
|
|
112
|
+
# @yieldparam object [Object] deserialized object
|
|
113
|
+
# @return nil
|
|
114
|
+
#
|
|
115
|
+
def each(&block)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
#
|
|
119
|
+
# Appends data into the internal buffer and repeats to deserialize objects.
|
|
120
|
+
# This method is equals to feed(data) && each.
|
|
121
|
+
#
|
|
122
|
+
# @param data [String]
|
|
123
|
+
# @yieldparam object [Object] deserialized object
|
|
124
|
+
# @return nil
|
|
125
|
+
#
|
|
126
|
+
def feed_each(data, &block)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
#
|
|
130
|
+
# Resets deserialization state of the unpacker and clears the internal buffer.
|
|
131
|
+
#
|
|
132
|
+
# @return nil
|
|
133
|
+
#
|
|
134
|
+
def reset
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
end
|
data/doclib/cbor.rb
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
module CBOR
|
|
2
|
+
#
|
|
3
|
+
# Serializes an object into an IO or String.
|
|
4
|
+
#
|
|
5
|
+
# @overload encode(obj)
|
|
6
|
+
# @return [String] serialized data
|
|
7
|
+
#
|
|
8
|
+
# @overload encode(obj, io)
|
|
9
|
+
# @return [IO]
|
|
10
|
+
#
|
|
11
|
+
def self.encode(arg)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
#
|
|
15
|
+
# Serializes an object into an IO or String. Alias of encode.
|
|
16
|
+
#
|
|
17
|
+
# @overload dump(obj)
|
|
18
|
+
# @return [String] serialized data
|
|
19
|
+
#
|
|
20
|
+
# @overload dump(obj, io)
|
|
21
|
+
# @return [IO]
|
|
22
|
+
#
|
|
23
|
+
def self.dump(arg)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
#
|
|
27
|
+
# Serializes an object into an IO or String. Alias of encode.
|
|
28
|
+
#
|
|
29
|
+
# @overload dump(obj)
|
|
30
|
+
# @return [String] serialized data
|
|
31
|
+
#
|
|
32
|
+
# @overload dump(obj, io)
|
|
33
|
+
# @return [IO]
|
|
34
|
+
#
|
|
35
|
+
def self.pack(arg)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
#
|
|
39
|
+
# Deserializes an object from an IO or String.
|
|
40
|
+
#
|
|
41
|
+
# @overload decode(string)
|
|
42
|
+
# @param string [String] data to deserialize
|
|
43
|
+
#
|
|
44
|
+
# @overload decode(io)
|
|
45
|
+
# @param io [IO]
|
|
46
|
+
#
|
|
47
|
+
# @return [Object] deserialized object
|
|
48
|
+
#
|
|
49
|
+
def self.decode(arg)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
#
|
|
53
|
+
# Deserializes an object from an IO or String. Alias of decode.
|
|
54
|
+
#
|
|
55
|
+
# @overload load(string)
|
|
56
|
+
# @param string [String] data to deserialize
|
|
57
|
+
#
|
|
58
|
+
# @overload load(io)
|
|
59
|
+
# @param io [IO]
|
|
60
|
+
#
|
|
61
|
+
# @return [Object] deserialized object
|
|
62
|
+
#
|
|
63
|
+
def self.load(arg)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
#
|
|
67
|
+
# Deserializes an object from an IO or String. Alias of decode.
|
|
68
|
+
#
|
|
69
|
+
# @overload unpack(string)
|
|
70
|
+
# @param string [String] data to deserialize
|
|
71
|
+
#
|
|
72
|
+
# @overload unpack(io)
|
|
73
|
+
# @param io [IO]
|
|
74
|
+
#
|
|
75
|
+
# @return [Object] deserialized object
|
|
76
|
+
#
|
|
77
|
+
def self.unpack(arg)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|