qpid_proton 0.18.1 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/cproton/cproton.c +863 -75
- data/lib/codec/data.rb +589 -815
- data/lib/codec/mapping.rb +142 -126
- data/lib/core/condition.rb +89 -0
- data/lib/core/connection.rb +188 -228
- data/lib/core/connection_driver.rb +202 -0
- data/lib/core/container.rb +366 -0
- data/lib/core/delivery.rb +76 -251
- data/lib/core/disposition.rb +21 -35
- data/lib/core/endpoint.rb +21 -53
- data/lib/core/event.rb +156 -0
- data/lib/core/exceptions.rb +109 -106
- data/lib/core/link.rb +24 -49
- data/lib/core/listener.rb +82 -0
- data/lib/core/message.rb +59 -155
- data/lib/core/messaging_handler.rb +190 -0
- data/lib/core/receiver.rb +38 -7
- data/lib/core/sasl.rb +43 -46
- data/lib/core/sender.rb +55 -32
- data/lib/core/session.rb +58 -58
- data/lib/core/ssl.rb +5 -13
- data/lib/core/ssl_details.rb +1 -2
- data/lib/core/ssl_domain.rb +5 -8
- data/lib/core/terminus.rb +62 -30
- data/lib/core/tracker.rb +45 -0
- data/lib/core/transfer.rb +121 -0
- data/lib/core/transport.rb +62 -97
- data/lib/core/uri.rb +73 -0
- data/lib/core/url.rb +11 -7
- data/lib/handler/adapter.rb +78 -0
- data/lib/handler/messaging_adapter.rb +127 -0
- data/lib/handler/messaging_handler.rb +128 -178
- data/lib/handler/reactor_messaging_adapter.rb +158 -0
- data/lib/messenger/messenger.rb +9 -8
- data/lib/messenger/subscription.rb +1 -2
- data/lib/messenger/tracker.rb +1 -2
- data/lib/messenger/tracker_status.rb +1 -2
- data/lib/qpid_proton.rb +36 -66
- data/lib/reactor/container.rb +40 -234
- data/lib/types/array.rb +73 -130
- data/lib/types/described.rb +2 -44
- data/lib/types/hash.rb +19 -56
- data/lib/types/strings.rb +1 -2
- data/lib/types/type.rb +68 -0
- data/lib/util/{handler.rb → deprecation.rb} +22 -15
- data/lib/util/error_handler.rb +4 -25
- data/lib/util/timeout.rb +1 -2
- data/lib/util/version.rb +1 -2
- data/lib/util/wrapper.rb +58 -38
- metadata +16 -33
- data/lib/core/base_handler.rb +0 -31
- data/lib/core/selectable.rb +0 -130
- data/lib/event/collector.rb +0 -148
- data/lib/event/event.rb +0 -318
- data/lib/event/event_base.rb +0 -91
- data/lib/event/event_type.rb +0 -71
- data/lib/handler/acking.rb +0 -70
- data/lib/handler/c_adaptor.rb +0 -47
- data/lib/handler/c_flow_controller.rb +0 -33
- data/lib/handler/endpoint_state_handler.rb +0 -217
- data/lib/handler/incoming_message_handler.rb +0 -74
- data/lib/handler/outgoing_message_handler.rb +0 -100
- data/lib/handler/wrapped_handler.rb +0 -76
- data/lib/reactor/acceptor.rb +0 -41
- data/lib/reactor/backoff.rb +0 -41
- data/lib/reactor/connector.rb +0 -115
- data/lib/reactor/global_overrides.rb +0 -44
- data/lib/reactor/link_option.rb +0 -90
- data/lib/reactor/reactor.rb +0 -196
- data/lib/reactor/session_per_connection.rb +0 -45
- data/lib/reactor/ssl_config.rb +0 -41
- data/lib/reactor/task.rb +0 -39
- data/lib/reactor/urls.rb +0 -45
- data/lib/util/class_wrapper.rb +0 -54
- data/lib/util/condition.rb +0 -47
- data/lib/util/constants.rb +0 -85
- data/lib/util/engine.rb +0 -82
- data/lib/util/reactor.rb +0 -32
- data/lib/util/swig_helper.rb +0 -114
- data/lib/util/uuid.rb +0 -32
data/lib/codec/data.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
#--
|
2
1
|
# Licensed to the Apache Software Foundation (ASF) under one
|
3
2
|
# or more contributor license agreements. See the NOTICE file
|
4
3
|
# distributed with this work for additional information
|
@@ -15,894 +14,669 @@
|
|
15
14
|
# KIND, either express or implied. See the License for the
|
16
15
|
# specific language governing permissions and limitations
|
17
16
|
# under the License.
|
18
|
-
#++
|
19
|
-
|
20
|
-
module Qpid::Proton::Codec
|
21
|
-
|
22
|
-
# +DataError+ is raised when an error occurs while encoding
|
23
|
-
# or decoding data.
|
24
|
-
class DataError < Exception; end
|
25
|
-
|
26
|
-
# The +Data+ class provides an interface for decoding, extracting,
|
27
|
-
# creating, and encoding arbitrary AMQP data. A +Data+ object
|
28
|
-
# contains a tree of AMQP values. Leaf nodes in this tree correspond
|
29
|
-
# to scalars in the AMQP type system such as INT or STRING. Interior
|
30
|
-
# nodes in this tree correspond to compound values in the AMQP type
|
31
|
-
# system such as *LIST*,*MAP*, *ARRAY*, or *DESCRIBED*. The root node
|
32
|
-
# of the tree is the +Data+ object itself and can have an arbitrary
|
33
|
-
# number of children.
|
34
|
-
#
|
35
|
-
# A +Data+ object maintains the notion of the current sibling node
|
36
|
-
# and a current parent node. Siblings are ordered within their parent.
|
37
|
-
# Values are accessed and/or added by using the #next, #prev,
|
38
|
-
# #enter, and #exit methods to navigate to the desired location in
|
39
|
-
# the tree and using the supplied variety of mutator and accessor
|
40
|
-
# methods to access or add a value of the desired type.
|
41
|
-
#
|
42
|
-
# The mutator methods will always add a value _after_ the current node
|
43
|
-
# in the tree. If the current node has a next sibling the mutator method
|
44
|
-
# will overwrite the value on this node. If there is no current node
|
45
|
-
# or the current node has no next sibling then one will be added. The
|
46
|
-
# accessor methods always set the added/modified node to the current
|
47
|
-
# node. The accessor methods read the value of the current node and do
|
48
|
-
# not change which node is current.
|
49
|
-
#
|
50
|
-
# The following types of scalar values are supported:
|
51
|
-
#
|
52
|
-
# * NULL
|
53
|
-
# * BOOL
|
54
|
-
# * UBYTE
|
55
|
-
# * BYTE
|
56
|
-
# * USHORT
|
57
|
-
# * SHORT
|
58
|
-
# * UINT
|
59
|
-
# * INT
|
60
|
-
# * CHAR
|
61
|
-
# * ULONG
|
62
|
-
# * LONG
|
63
|
-
# * TIMESTAMP
|
64
|
-
# * FLOAT
|
65
|
-
# * DOUBLE
|
66
|
-
# * DECIMAL32
|
67
|
-
# * DECIMAL64
|
68
|
-
# * DECIMAL128
|
69
|
-
# * UUID
|
70
|
-
# * BINARY
|
71
|
-
# * STRING
|
72
|
-
# * SYMBOL
|
73
|
-
#
|
74
|
-
# The following types of compound values are supported:
|
75
|
-
#
|
76
|
-
# * DESCRIBED
|
77
|
-
# * ARRAY
|
78
|
-
# * LIST
|
79
|
-
# * MAP
|
80
|
-
#
|
81
|
-
class Data
|
82
|
-
|
83
|
-
# Creates a new instance with the specified capacity.
|
84
|
-
#
|
85
|
-
# @param capacity [Integer, Object] The initial capacity or content.
|
86
|
-
#
|
87
|
-
def initialize(capacity = 16)
|
88
|
-
# TODO aconway 2017-08-11: error prone, confusion between capacity and Integer content.
|
89
|
-
if capacity.is_a?(Integer)
|
90
|
-
@data = Cproton.pn_data(capacity.to_i)
|
91
|
-
@free = true
|
92
|
-
else
|
93
|
-
@data = capacity
|
94
|
-
@free = false
|
95
|
-
end
|
96
|
-
|
97
|
-
# destructor
|
98
|
-
ObjectSpace.define_finalizer(self, self.class.finalize!(@data, @free))
|
99
|
-
end
|
100
17
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
18
|
+
module Qpid::Proton
|
19
|
+
# @private
|
20
|
+
module Codec
|
21
|
+
|
22
|
+
DataError = ::TypeError
|
23
|
+
|
24
|
+
# @private wrapper for pn_data_t*
|
25
|
+
# Raises TypeError for invalid conversions
|
26
|
+
class Data
|
27
|
+
|
28
|
+
# @private
|
29
|
+
PROTON_METHOD_PREFIX = "pn_data"
|
30
|
+
# @private
|
31
|
+
include Util::Wrapper
|
32
|
+
|
33
|
+
# @private
|
34
|
+
# Convert a pn_data_t* containing a single value to a ruby object.
|
35
|
+
# @return [Object, nil] The ruby value extracted from +impl+ or nil if impl is empty
|
36
|
+
def self.to_object(impl)
|
37
|
+
if (Cproton.pn_data_size(impl) > 0)
|
38
|
+
d = Data.new(impl)
|
39
|
+
d.rewind
|
40
|
+
d.next_object
|
41
|
+
end
|
42
|
+
end
|
107
43
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
44
|
+
# @private
|
45
|
+
# Clear a pn_data_t* and convert a ruby object into it. If x==nil leave it empty.
|
46
|
+
def self.from_object(impl, x)
|
47
|
+
d = Data.new(impl)
|
48
|
+
d.clear
|
49
|
+
d.object = x if x
|
50
|
+
nil
|
51
|
+
end
|
116
52
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
53
|
+
# @overload initialize(capacity)
|
54
|
+
# @param capacity [Integer] capacity for the new data instance.
|
55
|
+
# @overload instance(impl)
|
56
|
+
# @param impl [SWIG::pn_data_t*] wrap the C impl pointer.
|
57
|
+
def initialize(capacity = 16)
|
58
|
+
if capacity.is_a?(Integer)
|
59
|
+
@impl = Cproton.pn_data(capacity.to_i)
|
60
|
+
@free = true
|
61
|
+
else
|
62
|
+
# Assume non-integer capacity is a SWIG::pn_data_t*
|
63
|
+
@impl = capacity
|
64
|
+
@free = false
|
65
|
+
end
|
122
66
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
# #next will advance to the first node.
|
127
|
-
#
|
128
|
-
def rewind
|
129
|
-
Cproton.pn_data_rewind(@data)
|
130
|
-
end
|
67
|
+
# destructor
|
68
|
+
ObjectSpace.define_finalizer(self, self.class.finalize!(@impl, @free))
|
69
|
+
end
|
131
70
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
Cproton.pn_data_next(@data)
|
139
|
-
end
|
71
|
+
# @private
|
72
|
+
def self.finalize!(impl, free)
|
73
|
+
proc {
|
74
|
+
Cproton.pn_data_free(impl) if free
|
75
|
+
}
|
76
|
+
end
|
140
77
|
|
141
|
-
|
142
|
-
#
|
143
|
-
# If there is no previous sibling then the current node remains unchanged
|
144
|
-
# and nil is return.
|
145
|
-
#
|
146
|
-
def prev
|
147
|
-
return Cproton.pn_data_prev(@data) ? type : nil
|
148
|
-
end
|
78
|
+
proton_caller :clear, :rewind, :next, :prev, :enter, :exit
|
149
79
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
end
|
80
|
+
def enter_exit()
|
81
|
+
enter
|
82
|
+
yield self
|
83
|
+
ensure
|
84
|
+
exit
|
85
|
+
end
|
157
86
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
87
|
+
def code() Cproton.pn_data_type(@impl); end
|
88
|
+
|
89
|
+
def type() Mapping.for_code(Cproton.pn_data_type(@impl)); end
|
90
|
+
|
91
|
+
# Returns a representation of the data encoded in AMQP format.
|
92
|
+
def encode
|
93
|
+
buffer = "\0"*1024
|
94
|
+
loop do
|
95
|
+
cd = Cproton.pn_data_encode(@impl, buffer, buffer.length)
|
96
|
+
if cd == Cproton::PN_OVERFLOW
|
97
|
+
buffer *= 2
|
98
|
+
elsif cd >= 0
|
99
|
+
return buffer[0...cd]
|
100
|
+
else
|
101
|
+
check(cd)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
164
105
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
return (dtype == -1) ? nil : dtype
|
173
|
-
end
|
106
|
+
# Decodes the first value from supplied AMQP data and returns the number
|
107
|
+
# of bytes consumed.
|
108
|
+
#
|
109
|
+
# @param encoded [String] The encoded data.
|
110
|
+
def decode(encoded)
|
111
|
+
check(Cproton.pn_data_decode(@impl, encoded, encoded.length))
|
112
|
+
end
|
174
113
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
114
|
+
proton_is :described, :array_described
|
115
|
+
proton_caller :put_described
|
116
|
+
proton_caller :put_list, :get_list, :put_map, :get_map
|
117
|
+
proton_get :array_type
|
118
|
+
proton_caller :put_array
|
119
|
+
def get_array() [Cproton.pn_data_get_array(@impl), array_described?, array_type]; end
|
181
120
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
#
|
186
|
-
# @example
|
187
|
-
#
|
188
|
-
# @data.string = "This is a test."
|
189
|
-
# @encoded = @data.encode
|
190
|
-
#
|
191
|
-
# # @encoded now contains the text "This is a test." encoded for
|
192
|
-
# # AMQP transport.
|
193
|
-
#
|
194
|
-
def encode
|
195
|
-
buffer = "\0"*1024
|
196
|
-
loop do
|
197
|
-
cd = Cproton.pn_data_encode(@data, buffer, buffer.length)
|
198
|
-
if cd == Cproton::PN_OVERFLOW
|
199
|
-
buffer *= 2
|
200
|
-
elsif cd >= 0
|
201
|
-
return buffer[0...cd]
|
202
|
-
else
|
203
|
-
check(cd)
|
121
|
+
def expect(code)
|
122
|
+
unless code == self.code
|
123
|
+
raise TypeError, "expected #{Cproton.pn_type_name(code)}, got #{Cproton.pn_type_name(self.code)}"
|
204
124
|
end
|
205
125
|
end
|
206
|
-
end
|
207
|
-
|
208
|
-
# Decodes the first value from supplied AMQP data and returns the number
|
209
|
-
# of bytes consumed.
|
210
|
-
#
|
211
|
-
# @param encoded [String] The encoded data.
|
212
|
-
#
|
213
|
-
# @example
|
214
|
-
#
|
215
|
-
# # SCENARIO: A string of encoded data, @encoded, contains the text
|
216
|
-
# # of "This is a test." and is passed to an instance of Data
|
217
|
-
# # for decoding.
|
218
|
-
#
|
219
|
-
# @data.decode(@encoded)
|
220
|
-
# @data.string #=> "This is a test."
|
221
|
-
#
|
222
|
-
def decode(encoded)
|
223
|
-
check(Cproton.pn_data_decode(@data, encoded, encoded.length))
|
224
|
-
end
|
225
|
-
|
226
|
-
# Puts a list value.
|
227
|
-
#
|
228
|
-
# Elements may be filled by entering the list node and putting element
|
229
|
-
# values.
|
230
|
-
#
|
231
|
-
# @example
|
232
|
-
#
|
233
|
-
# data = Qpid::Proton::Codec::Data.new
|
234
|
-
# data.put_list
|
235
|
-
# data.enter
|
236
|
-
# data.int = 1
|
237
|
-
# data.int = 2
|
238
|
-
# data.int = 3
|
239
|
-
# data.exit
|
240
|
-
#
|
241
|
-
def put_list
|
242
|
-
check(Cproton.pn_data_put_list(@data))
|
243
|
-
end
|
244
126
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
#
|
250
|
-
# @example
|
251
|
-
#
|
252
|
-
# count = @data.list
|
253
|
-
# @data.enter
|
254
|
-
# (0...count).each
|
255
|
-
# type = @data.next
|
256
|
-
# puts "Value: #{@data.string}" if type == STRING
|
257
|
-
# # ... process other node types
|
258
|
-
# end
|
259
|
-
def list
|
260
|
-
Cproton.pn_data_get_list(@data)
|
261
|
-
end
|
127
|
+
def described
|
128
|
+
expect Cproton::PN_DESCRIBED
|
129
|
+
enter_exit { Types::Described.new(self.next_object, self.next_object) }
|
130
|
+
end
|
262
131
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
#
|
268
|
-
# @example
|
269
|
-
#
|
270
|
-
# data = Qpid::Proton::Codec::Data.new
|
271
|
-
# data.put_map
|
272
|
-
# data.enter
|
273
|
-
# data.string = "key"
|
274
|
-
# data.string = "value"
|
275
|
-
# data.exit
|
276
|
-
#
|
277
|
-
def put_map
|
278
|
-
check(Cproton.pn_data_put_map(@data))
|
279
|
-
end
|
132
|
+
def described= d
|
133
|
+
put_described
|
134
|
+
enter_exit { self << d.descriptor << d.value }
|
135
|
+
end
|
280
136
|
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
# @example
|
287
|
-
#
|
288
|
-
# count = @data.map
|
289
|
-
# @data.enter
|
290
|
-
# (0...count).each do
|
291
|
-
# type = @data.next
|
292
|
-
# puts "Key=#{@data.string}" if type == STRING
|
293
|
-
# # ... process other key types
|
294
|
-
# type = @data.next
|
295
|
-
# puts "Value=#{@data.string}" if type == STRING
|
296
|
-
# # ... process other value types
|
297
|
-
# end
|
298
|
-
# @data.exit
|
299
|
-
def map
|
300
|
-
Cproton.pn_data_get_map(@data)
|
301
|
-
end
|
137
|
+
def fill(a, count, what)
|
138
|
+
a << self.object while self.next
|
139
|
+
raise TypeError, "#{what} expected #{count} elements, got #{a.size}" unless a.size == count
|
140
|
+
a
|
141
|
+
end
|
302
142
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
143
|
+
def list
|
144
|
+
return array if code == Cproton::PN_ARRAY
|
145
|
+
expect Cproton::PN_LIST
|
146
|
+
count = get_list
|
147
|
+
a = []
|
148
|
+
enter_exit { fill(a, count, __method__) }
|
149
|
+
end
|
307
150
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
# type.
|
313
|
-
#
|
314
|
-
# If an array is *described* then the first child value of the array
|
315
|
-
# is the descriptor and may be of any type.
|
316
|
-
#
|
317
|
-
# @param described [Boolean] True if the array is described.
|
318
|
-
# @param element_type [Integer] The AMQP type for each element of the array.
|
319
|
-
#
|
320
|
-
# @example
|
321
|
-
#
|
322
|
-
# # create an array of integer values
|
323
|
-
# data = Qpid::Proton::Codec::Data.new
|
324
|
-
# data.put_array(false, INT)
|
325
|
-
# data.enter
|
326
|
-
# data.int = 1
|
327
|
-
# data.int = 2
|
328
|
-
# data.int = 3
|
329
|
-
# data.exit
|
330
|
-
#
|
331
|
-
# # create a described array of double values
|
332
|
-
# data.put_array(true, DOUBLE)
|
333
|
-
# data.enter
|
334
|
-
# data.symbol = "array-descriptor"
|
335
|
-
# data.double = 1.1
|
336
|
-
# data.double = 1.2
|
337
|
-
# data.double = 1.3
|
338
|
-
# data.exit
|
339
|
-
#
|
340
|
-
def put_array(described, element_type)
|
341
|
-
check(Cproton.pn_data_put_array(@data, described, element_type.code))
|
342
|
-
end
|
151
|
+
def list=(a)
|
152
|
+
put_list
|
153
|
+
enter_exit { a.each { |x| self << x } }
|
154
|
+
end
|
343
155
|
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
#
|
355
|
-
# # enter the node
|
356
|
-
# data.enter
|
357
|
-
#
|
358
|
-
# # get the next node
|
359
|
-
# data.next
|
360
|
-
# puts "Descriptor: #{data.symbol}" if described
|
361
|
-
# (0...count).each do
|
362
|
-
# @data.next
|
363
|
-
# puts "Element: #{@data.string}"
|
364
|
-
# end
|
365
|
-
def array
|
366
|
-
count = Cproton.pn_data_get_array(@data)
|
367
|
-
described = Cproton.pn_data_is_array_described(@data)
|
368
|
-
array_type = Cproton.pn_data_get_array_type(@data)
|
369
|
-
return nil if array_type == -1
|
370
|
-
[count, described, Mapping.for_code(array_type) ]
|
371
|
-
end
|
156
|
+
def array
|
157
|
+
return list if code == Cproton::PN_LIST
|
158
|
+
expect Cproton::PN_ARRAY
|
159
|
+
count, d, t = get_array
|
160
|
+
enter_exit do
|
161
|
+
desc = next_object if d
|
162
|
+
a = Types::UniformArray.new(t, nil, desc)
|
163
|
+
fill(a, count, "array")
|
164
|
+
end
|
165
|
+
end
|
372
166
|
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
167
|
+
def array=(a)
|
168
|
+
t = a.type if a.respond_to? :type
|
169
|
+
d = a.descriptor if a.respond_to? :descriptor
|
170
|
+
if (h = a.instance_variable_get(:@proton_array_header))
|
171
|
+
t ||= h.type
|
172
|
+
d ||= h.descriptor
|
173
|
+
end
|
174
|
+
raise TypeError, "no type when converting #{a.class} to an array" unless t
|
175
|
+
put_array(!d.nil?, t.code)
|
176
|
+
m = Mapping[t]
|
177
|
+
enter_exit do
|
178
|
+
self << d unless d.nil?
|
179
|
+
a.each { |e| m.put(self, e); }
|
180
|
+
end
|
181
|
+
end
|
377
182
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
# data.symbol = "value-descriptor"
|
390
|
-
# data.string = "the value"
|
391
|
-
# data.exit
|
392
|
-
#
|
393
|
-
def put_described
|
394
|
-
check(Cproton.pn_data_put_described(@data))
|
395
|
-
end
|
183
|
+
def map
|
184
|
+
expect Cproton::PN_MAP
|
185
|
+
count = self.get_map
|
186
|
+
raise TypeError, "invalid map, total of keys and values is odd" if count.odd?
|
187
|
+
enter_exit do
|
188
|
+
m = {}
|
189
|
+
m[object] = next_object while self.next
|
190
|
+
raise TypeError, "map expected #{count/2} entries, got #{m.size}" unless m.size == count/2
|
191
|
+
m
|
192
|
+
end
|
193
|
+
end
|
396
194
|
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
self.next
|
402
|
-
type = self.type
|
403
|
-
descriptor = type.get(self)
|
404
|
-
self.next
|
405
|
-
type = self.type
|
406
|
-
value = type.get(self)
|
407
|
-
self.exit
|
408
|
-
Qpid::Proton::Types::Described.new(descriptor, value)
|
409
|
-
end
|
195
|
+
def map= m
|
196
|
+
put_map
|
197
|
+
enter_exit { m.each_pair { |k,v| self << k << v } }
|
198
|
+
end
|
410
199
|
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
200
|
+
# Return nil if vallue is null, raise exception otherwise.
|
201
|
+
def null() raise TypeError, "expected null, got #{type || 'empty'}" unless null?; end
|
202
|
+
|
203
|
+
# Set the current value to null
|
204
|
+
def null=(dummy=nil) check(Cproton.pn_data_put_null(@impl)); end
|
205
|
+
|
206
|
+
# Puts an arbitrary object type.
|
207
|
+
#
|
208
|
+
# The Data instance will determine which AMQP type is appropriate and will
|
209
|
+
# use that to encode the object.
|
210
|
+
#
|
211
|
+
# @param object [Object] The value.
|
212
|
+
#
|
213
|
+
def object=(object)
|
214
|
+
Mapping.for_class(object.class).put(self, object)
|
215
|
+
object
|
216
|
+
end
|
425
217
|
|
426
|
-
|
427
|
-
|
428
|
-
def null
|
429
|
-
check(Cproton.pn_data_put_null(@data))
|
430
|
-
end
|
218
|
+
# Add an arbitrary data value using object=, return self
|
219
|
+
def <<(x) self.object=x; self; end
|
431
220
|
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
null
|
438
|
-
end
|
221
|
+
# Move forward to the next value and return it
|
222
|
+
def next_object
|
223
|
+
self.next or raise TypeError, "not enough data"
|
224
|
+
self.object
|
225
|
+
end
|
439
226
|
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
def object=(object)
|
448
|
-
Mapping.for_class(object.class).put(self, object)
|
449
|
-
end
|
227
|
+
# Gets the current node, based on how it was encoded.
|
228
|
+
#
|
229
|
+
# @return [Object] The current node.
|
230
|
+
#
|
231
|
+
def object
|
232
|
+
self.type.get(self) if self.type
|
233
|
+
end
|
450
234
|
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
type.get(data)
|
459
|
-
end
|
235
|
+
# Checks if the current node is null.
|
236
|
+
#
|
237
|
+
# @return [Boolean] True if the node is null.
|
238
|
+
#
|
239
|
+
def null?
|
240
|
+
Cproton.pn_data_is_null(@impl)
|
241
|
+
end
|
460
242
|
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
243
|
+
# Puts a boolean value.
|
244
|
+
#
|
245
|
+
# @param value [Boolean] The boolean value.
|
246
|
+
#
|
247
|
+
def bool=(value)
|
248
|
+
check(Cproton.pn_data_put_bool(@impl, value))
|
249
|
+
end
|
468
250
|
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
251
|
+
# If the current node is a boolean, then it returns the value. Otherwise,
|
252
|
+
# it returns false.
|
253
|
+
#
|
254
|
+
# @return [Boolean] The boolean value.
|
255
|
+
#
|
256
|
+
def bool
|
257
|
+
Cproton.pn_data_get_bool(@impl)
|
258
|
+
end
|
476
259
|
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
end
|
260
|
+
# Puts an unsigned byte value.
|
261
|
+
#
|
262
|
+
# @param value [Integer] The unsigned byte value.
|
263
|
+
#
|
264
|
+
def ubyte=(value)
|
265
|
+
check(Cproton.pn_data_put_ubyte(@impl, value))
|
266
|
+
end
|
485
267
|
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
268
|
+
# If the current node is an unsigned byte, returns its value. Otherwise,
|
269
|
+
# it returns 0.
|
270
|
+
#
|
271
|
+
# @return [Integer] The unsigned byte value.
|
272
|
+
#
|
273
|
+
def ubyte
|
274
|
+
Cproton.pn_data_get_ubyte(@impl)
|
275
|
+
end
|
493
276
|
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
end
|
277
|
+
# Puts a byte value.
|
278
|
+
#
|
279
|
+
# @param value [Integer] The byte value.
|
280
|
+
#
|
281
|
+
def byte=(value)
|
282
|
+
check(Cproton.pn_data_put_byte(@impl, value))
|
283
|
+
end
|
502
284
|
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
285
|
+
# If the current node is an byte, returns its value. Otherwise,
|
286
|
+
# it returns 0.
|
287
|
+
#
|
288
|
+
# @return [Integer] The byte value.
|
289
|
+
#
|
290
|
+
def byte
|
291
|
+
Cproton.pn_data_get_byte(@impl)
|
292
|
+
end
|
510
293
|
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
end
|
294
|
+
# Puts an unsigned short value.
|
295
|
+
#
|
296
|
+
# @param value [Integer] The unsigned short value
|
297
|
+
#
|
298
|
+
def ushort=(value)
|
299
|
+
check(Cproton.pn_data_put_ushort(@impl, value))
|
300
|
+
end
|
519
301
|
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
302
|
+
# If the current node is an unsigned short, returns its value. Otherwise,
|
303
|
+
# it returns 0.
|
304
|
+
#
|
305
|
+
# @return [Integer] The unsigned short value.
|
306
|
+
#
|
307
|
+
def ushort
|
308
|
+
Cproton.pn_data_get_ushort(@impl)
|
309
|
+
end
|
527
310
|
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
end
|
311
|
+
# Puts a short value.
|
312
|
+
#
|
313
|
+
# @param value [Integer] The short value.
|
314
|
+
#
|
315
|
+
def short=(value)
|
316
|
+
check(Cproton.pn_data_put_short(@impl, value))
|
317
|
+
end
|
536
318
|
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
319
|
+
# If the current node is a short, returns its value. Otherwise,
|
320
|
+
# returns a 0.
|
321
|
+
#
|
322
|
+
# @return [Integer] The short value.
|
323
|
+
#
|
324
|
+
def short
|
325
|
+
Cproton.pn_data_get_short(@impl)
|
326
|
+
end
|
544
327
|
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
328
|
+
# Puts an unsigned integer value.
|
329
|
+
#
|
330
|
+
# @param value [Integer] the unsigned integer value
|
331
|
+
#
|
332
|
+
def uint=(value)
|
333
|
+
raise TypeError if value.nil?
|
334
|
+
raise RangeError, "invalid uint: #{value}" if value < 0
|
335
|
+
check(Cproton.pn_data_put_uint(@impl, value))
|
336
|
+
end
|
553
337
|
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
end
|
338
|
+
# If the current node is an unsigned int, returns its value. Otherwise,
|
339
|
+
# returns 0.
|
340
|
+
#
|
341
|
+
# @return [Integer] The unsigned integer value.
|
342
|
+
#
|
343
|
+
def uint
|
344
|
+
Cproton.pn_data_get_uint(@impl)
|
345
|
+
end
|
563
346
|
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
347
|
+
# Puts an integer value.
|
348
|
+
#
|
349
|
+
# ==== Options
|
350
|
+
#
|
351
|
+
# * value - the integer value
|
352
|
+
def int=(value)
|
353
|
+
check(Cproton.pn_data_put_int(@impl, value))
|
354
|
+
end
|
572
355
|
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
356
|
+
# If the current node is an integer, returns its value. Otherwise,
|
357
|
+
# returns 0.
|
358
|
+
#
|
359
|
+
# @return [Integer] The integer value.
|
360
|
+
#
|
361
|
+
def int
|
362
|
+
Cproton.pn_data_get_int(@impl)
|
363
|
+
end
|
581
364
|
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
end
|
365
|
+
# Puts a character value.
|
366
|
+
#
|
367
|
+
# @param value [Integer] The character value.
|
368
|
+
#
|
369
|
+
def char=(value)
|
370
|
+
check(Cproton.pn_data_put_char(@impl, value))
|
371
|
+
end
|
590
372
|
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
373
|
+
# If the current node is a character, returns its value. Otherwise,
|
374
|
+
# returns 0.
|
375
|
+
#
|
376
|
+
# @return [Integer] The character value.
|
377
|
+
#
|
378
|
+
def char
|
379
|
+
Cproton.pn_data_get_char(@impl)
|
380
|
+
end
|
598
381
|
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
382
|
+
# Puts an unsigned long value.
|
383
|
+
#
|
384
|
+
# @param value [Integer] The unsigned long value.
|
385
|
+
#
|
386
|
+
def ulong=(value)
|
387
|
+
raise TypeError if value.nil?
|
388
|
+
raise RangeError, "invalid ulong: #{value}" if value < 0
|
389
|
+
check(Cproton.pn_data_put_ulong(@impl, value))
|
390
|
+
end
|
607
391
|
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
end
|
392
|
+
# If the current node is an unsigned long, returns its value. Otherwise,
|
393
|
+
# returns 0.
|
394
|
+
#
|
395
|
+
# @return [Integer] The unsigned long value.
|
396
|
+
#
|
397
|
+
def ulong
|
398
|
+
Cproton.pn_data_get_ulong(@impl)
|
399
|
+
end
|
617
400
|
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
end
|
401
|
+
# Puts a long value.
|
402
|
+
#
|
403
|
+
# @param value [Integer] The long value.
|
404
|
+
#
|
405
|
+
def long=(value)
|
406
|
+
check(Cproton.pn_data_put_long(@impl, value))
|
407
|
+
end
|
626
408
|
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
end
|
409
|
+
# If the current node is a long, returns its value. Otherwise, returns 0.
|
410
|
+
#
|
411
|
+
# @return [Integer] The long value.
|
412
|
+
def long
|
413
|
+
Cproton.pn_data_get_long(@impl)
|
414
|
+
end
|
634
415
|
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
416
|
+
# Puts a timestamp value.
|
417
|
+
#
|
418
|
+
# @param value [Integer] The timestamp value.
|
419
|
+
#
|
420
|
+
def timestamp=(value)
|
421
|
+
value = value.to_i if (!value.nil? && value.is_a?(Time))
|
422
|
+
check(Cproton.pn_data_put_timestamp(@impl, value))
|
423
|
+
end
|
641
424
|
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
425
|
+
# If the current node is a timestamp, returns its value. Otherwise,
|
426
|
+
# returns 0.
|
427
|
+
#
|
428
|
+
# @return [Integer] The timestamp value.
|
429
|
+
#
|
430
|
+
def timestamp
|
431
|
+
Cproton.pn_data_get_timestamp(@impl)
|
432
|
+
end
|
650
433
|
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
end
|
434
|
+
# Puts a float value.
|
435
|
+
#
|
436
|
+
# @param value [Float] The floating point value.
|
437
|
+
#
|
438
|
+
def float=(value)
|
439
|
+
check(Cproton.pn_data_put_float(@impl, value))
|
440
|
+
end
|
659
441
|
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
442
|
+
# If the current node is a float, returns its value. Otherwise,
|
443
|
+
# returns 0.
|
444
|
+
#
|
445
|
+
# @return [Float] The floating point value.
|
446
|
+
#
|
447
|
+
def float
|
448
|
+
Cproton.pn_data_get_float(@impl)
|
449
|
+
end
|
667
450
|
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
end
|
451
|
+
# Puts a double value.
|
452
|
+
#
|
453
|
+
# @param value [Float] The double precision floating point value.
|
454
|
+
#
|
455
|
+
def double=(value)
|
456
|
+
check(Cproton.pn_data_put_double(@impl, value))
|
457
|
+
end
|
676
458
|
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
459
|
+
# If the current node is a double, returns its value. Otherwise,
|
460
|
+
# returns 0.
|
461
|
+
#
|
462
|
+
# @return [Float] The double precision floating point value.
|
463
|
+
#
|
464
|
+
def double
|
465
|
+
Cproton.pn_data_get_double(@impl)
|
466
|
+
end
|
684
467
|
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
end
|
468
|
+
# Puts a decimal32 value.
|
469
|
+
#
|
470
|
+
# @param value [Integer] The decimal32 value.
|
471
|
+
#
|
472
|
+
def decimal32=(value)
|
473
|
+
check(Cproton.pn_data_put_decimal32(@impl, value))
|
474
|
+
end
|
693
475
|
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
476
|
+
# If the current node is a decimal32, returns its value. Otherwise,
|
477
|
+
# returns 0.
|
478
|
+
#
|
479
|
+
# @return [Integer] The decimal32 value.
|
480
|
+
#
|
481
|
+
def decimal32
|
482
|
+
Cproton.pn_data_get_decimal32(@impl)
|
483
|
+
end
|
701
484
|
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
end
|
485
|
+
# Puts a decimal64 value.
|
486
|
+
#
|
487
|
+
# @param value [Integer] The decimal64 value.
|
488
|
+
#
|
489
|
+
def decimal64=(value)
|
490
|
+
check(Cproton.pn_data_put_decimal64(@impl, value))
|
491
|
+
end
|
710
492
|
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
493
|
+
# If the current node is a decimal64, returns its value. Otherwise,
|
494
|
+
# it returns 0.
|
495
|
+
#
|
496
|
+
# @return [Integer] The decimal64 value.
|
497
|
+
#
|
498
|
+
def decimal64
|
499
|
+
Cproton.pn_data_get_decimal64(@impl)
|
500
|
+
end
|
718
501
|
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
502
|
+
# Puts a decimal128 value.
|
503
|
+
#
|
504
|
+
# @param value [Integer] The decimal128 value.
|
505
|
+
#
|
506
|
+
def decimal128=(value)
|
507
|
+
raise TypeError, "invalid decimal128 value: #{value}" if value.nil?
|
508
|
+
value = value.to_s(16).rjust(32, "0")
|
509
|
+
bytes = []
|
510
|
+
value.scan(/(..)/) {|v| bytes << v[0].to_i(16)}
|
511
|
+
check(Cproton.pn_data_put_decimal128(@impl, bytes))
|
512
|
+
end
|
727
513
|
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
end
|
514
|
+
# If the current node is a decimal128, returns its value. Otherwise,
|
515
|
+
# returns 0.
|
516
|
+
#
|
517
|
+
# @return [Integer] The decimal128 value.
|
518
|
+
#
|
519
|
+
def decimal128
|
520
|
+
value = ""
|
521
|
+
Cproton.pn_data_get_decimal128(@impl).each{|val| value += ("%02x" % val)}
|
522
|
+
value.to_i(16)
|
523
|
+
end
|
739
524
|
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
525
|
+
# Puts a +UUID+ value.
|
526
|
+
#
|
527
|
+
# The UUID is expected to be in the format of a string or else a 128-bit
|
528
|
+
# integer value.
|
529
|
+
#
|
530
|
+
# @param value [String, Numeric] A string or numeric representation of the UUID.
|
531
|
+
#
|
532
|
+
# @example
|
533
|
+
#
|
534
|
+
# # set a uuid value from a string value
|
535
|
+
# require 'securerandom'
|
536
|
+
# @impl.uuid = SecureRandom.uuid
|
537
|
+
#
|
538
|
+
# # or
|
539
|
+
# @impl.uuid = "fd0289a5-8eec-4a08-9283-81d02c9d2fff"
|
540
|
+
#
|
541
|
+
# # set a uuid value from a 128-bit value
|
542
|
+
# @impl.uuid = 0 # sets to 00000000-0000-0000-0000-000000000000
|
543
|
+
#
|
544
|
+
def uuid=(value)
|
545
|
+
raise ::ArgumentError, "invalid uuid: #{value}" if value.nil?
|
546
|
+
|
547
|
+
# if the uuid that was submitted was numeric value, then translated
|
548
|
+
# it into a hex string, otherwise assume it was a string represtation
|
549
|
+
# and attempt to decode it
|
550
|
+
if value.is_a? Numeric
|
551
|
+
value = "%032x" % value
|
552
|
+
else
|
553
|
+
raise ::ArgumentError, "invalid uuid: #{value}" if !valid_uuid?(value)
|
750
554
|
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
# require 'securerandom'
|
762
|
-
# @data.uuid = SecureRandom.uuid
|
763
|
-
#
|
764
|
-
# # or
|
765
|
-
# @data.uuid = "fd0289a5-8eec-4a08-9283-81d02c9d2fff"
|
766
|
-
#
|
767
|
-
# # set a uuid value from a 128-bit value
|
768
|
-
# @data.uuid = 0 # sets to 00000000-0000-0000-0000-000000000000
|
769
|
-
#
|
770
|
-
def uuid=(value)
|
771
|
-
raise ::ArgumentError, "invalid uuid: #{value}" if value.nil?
|
772
|
-
|
773
|
-
# if the uuid that was submitted was numeric value, then translated
|
774
|
-
# it into a hex string, otherwise assume it was a string represtation
|
775
|
-
# and attempt to decode it
|
776
|
-
if value.is_a? Numeric
|
777
|
-
value = "%032x" % value
|
778
|
-
else
|
779
|
-
raise ::ArgumentError, "invalid uuid: #{value}" if !valid_uuid?(value)
|
780
|
-
|
781
|
-
value = (value[0, 8] +
|
782
|
-
value[9, 4] +
|
783
|
-
value[14, 4] +
|
784
|
-
value[19, 4] +
|
785
|
-
value[24, 12])
|
786
|
-
end
|
787
|
-
bytes = []
|
788
|
-
value.scan(/(..)/) {|v| bytes << v[0].to_i(16)}
|
789
|
-
check(Cproton.pn_data_put_uuid(@data, bytes))
|
790
|
-
end
|
555
|
+
value = (value[0, 8] +
|
556
|
+
value[9, 4] +
|
557
|
+
value[14, 4] +
|
558
|
+
value[19, 4] +
|
559
|
+
value[24, 12])
|
560
|
+
end
|
561
|
+
bytes = []
|
562
|
+
value.scan(/(..)/) {|v| bytes << v[0].to_i(16)}
|
563
|
+
check(Cproton.pn_data_put_uuid(@impl, bytes))
|
564
|
+
end
|
791
565
|
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
566
|
+
# If the current value is a +UUID+, returns its value. Otherwise,
|
567
|
+
# it returns nil.
|
568
|
+
#
|
569
|
+
# @return [String] The string representation of the UUID.
|
570
|
+
#
|
571
|
+
def uuid
|
572
|
+
value = ""
|
573
|
+
Cproton.pn_data_get_uuid(@impl).each{|val| value += ("%02x" % val)}
|
574
|
+
value.insert(8, "-").insert(13, "-").insert(18, "-").insert(23, "-")
|
575
|
+
end
|
802
576
|
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
577
|
+
# Puts a binary value.
|
578
|
+
#
|
579
|
+
# A binary string is encoded as an ASCII 8-bit string value. This is in
|
580
|
+
# contranst to other strings, which are treated as UTF-8 encoded.
|
581
|
+
#
|
582
|
+
# @param value [String] An arbitrary string value.
|
583
|
+
#
|
584
|
+
# @see #string=
|
585
|
+
#
|
586
|
+
def binary=(value)
|
587
|
+
check(Cproton.pn_data_put_binary(@impl, value))
|
588
|
+
end
|
815
589
|
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
590
|
+
# If the current node is binary, returns its value. Otherwise, it returns
|
591
|
+
# an empty string ("").
|
592
|
+
#
|
593
|
+
# @return [String] The binary string.
|
594
|
+
#
|
595
|
+
# @see #string
|
596
|
+
#
|
597
|
+
def binary
|
598
|
+
Qpid::Proton::Types::BinaryString.new(Cproton.pn_data_get_binary(@impl))
|
599
|
+
end
|
826
600
|
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
601
|
+
# Puts a UTF-8 encoded string value.
|
602
|
+
#
|
603
|
+
# *NOTE:* A nil value is stored as an empty string rather than as a nil.
|
604
|
+
#
|
605
|
+
# @param value [String] The UTF-8 encoded string value.
|
606
|
+
#
|
607
|
+
# @see #binary=
|
608
|
+
#
|
609
|
+
def string=(value)
|
610
|
+
check(Cproton.pn_data_put_string(@impl, value))
|
611
|
+
end
|
838
612
|
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
613
|
+
# If the current node is a string, returns its value. Otherwise, it
|
614
|
+
# returns an empty string ("").
|
615
|
+
#
|
616
|
+
# @return [String] The UTF-8 encoded string.
|
617
|
+
#
|
618
|
+
# @see #binary
|
619
|
+
#
|
620
|
+
def string
|
621
|
+
Qpid::Proton::Types::UTFString.new(Cproton.pn_data_get_string(@impl))
|
622
|
+
end
|
849
623
|
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
624
|
+
# Puts a symbolic value.
|
625
|
+
#
|
626
|
+
# @param value [String|Symbol] The symbolic string value.
|
627
|
+
#
|
628
|
+
def symbol=(value)
|
629
|
+
check(Cproton.pn_data_put_symbol(@impl, value.to_s))
|
630
|
+
end
|
857
631
|
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
632
|
+
# If the current node is a symbol, returns its value. Otherwise, it
|
633
|
+
# returns an empty string ("").
|
634
|
+
#
|
635
|
+
# @return [Symbol] The symbol value.
|
636
|
+
#
|
637
|
+
def symbol
|
638
|
+
Cproton.pn_data_get_symbol(@impl).to_sym
|
639
|
+
end
|
866
640
|
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
641
|
+
# Get the current value as a single object.
|
642
|
+
#
|
643
|
+
# @return [Object] The current node's object.
|
644
|
+
#
|
645
|
+
# @see #type_code
|
646
|
+
# @see #type
|
647
|
+
#
|
648
|
+
def get
|
649
|
+
type.get(self);
|
650
|
+
end
|
877
651
|
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
652
|
+
# Puts a new value with the given type into the current node.
|
653
|
+
#
|
654
|
+
# @param value [Object] The value.
|
655
|
+
# @param type_code [Mapping] The value's type.
|
656
|
+
#
|
657
|
+
# @private
|
658
|
+
#
|
659
|
+
def put(value, type_code);
|
660
|
+
type_code.put(self, value);
|
661
|
+
end
|
888
662
|
|
889
|
-
|
663
|
+
private
|
890
664
|
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
665
|
+
def valid_uuid?(value)
|
666
|
+
# ensure that the UUID is in the right format
|
667
|
+
# xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
|
668
|
+
value =~ /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/
|
669
|
+
end
|
896
670
|
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
671
|
+
# @private
|
672
|
+
def check(err)
|
673
|
+
if err < 0
|
674
|
+
raise TypeError, "[#{err}]: #{Cproton.pn_data_error(@impl)}"
|
675
|
+
else
|
676
|
+
return err
|
677
|
+
end
|
903
678
|
end
|
904
|
-
end
|
905
679
|
|
680
|
+
end
|
906
681
|
end
|
907
|
-
|
908
682
|
end
|