qpid_proton 0.9.0 → 0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/lib/codec/data.rb +912 -0
  3. data/lib/codec/mapping.rb +169 -0
  4. data/lib/{qpid_proton/tracker.rb → core/base_handler.rb} +4 -15
  5. data/lib/core/connection.rb +328 -0
  6. data/lib/core/delivery.rb +271 -0
  7. data/lib/core/disposition.rb +158 -0
  8. data/lib/core/endpoint.rb +140 -0
  9. data/lib/{qpid_proton → core}/exceptions.rb +43 -2
  10. data/lib/core/link.rb +387 -0
  11. data/lib/core/message.rb +633 -0
  12. data/lib/core/receiver.rb +95 -0
  13. data/lib/core/sasl.rb +94 -0
  14. data/lib/core/selectable.rb +130 -0
  15. data/lib/core/sender.rb +76 -0
  16. data/lib/core/session.rb +163 -0
  17. data/lib/core/ssl.rb +164 -0
  18. data/lib/{qpid_proton/version.rb → core/ssl_details.rb} +7 -6
  19. data/lib/core/ssl_domain.rb +156 -0
  20. data/lib/core/terminus.rb +218 -0
  21. data/lib/core/transport.rb +411 -0
  22. data/lib/core/url.rb +77 -0
  23. data/lib/event/collector.rb +148 -0
  24. data/lib/event/event.rb +318 -0
  25. data/lib/event/event_base.rb +91 -0
  26. data/lib/event/event_type.rb +71 -0
  27. data/lib/handler/acking.rb +70 -0
  28. data/lib/handler/c_adaptor.rb +47 -0
  29. data/lib/handler/c_flow_controller.rb +33 -0
  30. data/lib/handler/endpoint_state_handler.rb +217 -0
  31. data/lib/handler/incoming_message_handler.rb +74 -0
  32. data/lib/handler/messaging_handler.rb +218 -0
  33. data/lib/handler/outgoing_message_handler.rb +98 -0
  34. data/lib/handler/wrapped_handler.rb +76 -0
  35. data/lib/messenger/messenger.rb +702 -0
  36. data/lib/messenger/subscription.rb +37 -0
  37. data/lib/messenger/tracker.rb +38 -0
  38. data/lib/messenger/tracker_status.rb +69 -0
  39. data/lib/qpid_proton.rb +106 -16
  40. data/lib/reactor/acceptor.rb +41 -0
  41. data/lib/reactor/backoff.rb +41 -0
  42. data/lib/reactor/connector.rb +98 -0
  43. data/lib/reactor/container.rb +272 -0
  44. data/lib/reactor/global_overrides.rb +44 -0
  45. data/lib/reactor/link_option.rb +90 -0
  46. data/lib/reactor/reactor.rb +198 -0
  47. data/lib/reactor/session_per_connection.rb +45 -0
  48. data/lib/reactor/ssl_config.rb +41 -0
  49. data/lib/reactor/task.rb +39 -0
  50. data/lib/{qpid_proton/subscription.rb → reactor/urls.rb} +12 -13
  51. data/lib/{qpid_proton → types}/array.rb +28 -29
  52. data/lib/types/described.rb +63 -0
  53. data/lib/{qpid_proton → types}/hash.rb +4 -3
  54. data/lib/types/strings.rb +62 -0
  55. data/lib/util/class_wrapper.rb +54 -0
  56. data/lib/util/condition.rb +45 -0
  57. data/lib/util/constants.rb +85 -0
  58. data/lib/util/engine.rb +82 -0
  59. data/lib/util/error_handler.rb +127 -0
  60. data/lib/util/handler.rb +41 -0
  61. data/lib/util/reactor.rb +32 -0
  62. data/lib/util/swig_helper.rb +114 -0
  63. data/lib/util/timeout.rb +50 -0
  64. data/lib/util/uuid.rb +32 -0
  65. data/lib/util/version.rb +30 -0
  66. data/lib/util/wrapper.rb +124 -0
  67. metadata +67 -21
  68. data/ext/cproton/cproton.c +0 -22196
  69. data/lib/qpid_proton/data.rb +0 -788
  70. data/lib/qpid_proton/described.rb +0 -66
  71. data/lib/qpid_proton/exception_handling.rb +0 -127
  72. data/lib/qpid_proton/filters.rb +0 -67
  73. data/lib/qpid_proton/mapping.rb +0 -170
  74. data/lib/qpid_proton/message.rb +0 -621
  75. data/lib/qpid_proton/messenger.rb +0 -702
  76. data/lib/qpid_proton/selectable.rb +0 -126
  77. data/lib/qpid_proton/strings.rb +0 -65
  78. data/lib/qpid_proton/tracker_status.rb +0 -73
@@ -1,788 +0,0 @@
1
- #--
2
- # Licensed to the Apache Software Foundation (ASF) under one
3
- # or more contributor license agreements. See the NOTICE file
4
- # distributed with this work for additional information
5
- # regarding copyright ownership. The ASF licenses this file
6
- # to you under the Apache License, Version 2.0 (the
7
- # "License"); you may not use this file except in compliance
8
- # with the License. You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing,
13
- # software distributed under the License is distributed on an
14
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- # KIND, either express or implied. See the License for the
16
- # specific language governing permissions and limitations
17
- # under the License.
18
- #++
19
-
20
- module Qpid # :nodoc:
21
-
22
- module Proton # :nodoc:
23
-
24
- # +DataError+ is raised when an error occurs while encoding
25
- # or decoding data.
26
- class DataError < Exception; end
27
-
28
- # The +Data+ class provides an interface for decoding, extracting,
29
- # creating, and encoding arbitrary AMQP data. A +Data+ object
30
- # contains a tree of AMQP values. Leaf nodes in this tree correspond
31
- # to scalars in the AMQP type system such as INT or STRING. Interior
32
- # nodes in this tree correspond to compound values in the AMQP type
33
- # system such as *LIST*,*MAP*, *ARRAY*, or *DESCRIBED*. The root node
34
- # of the tree is the +Data+ object itself and can have an arbitrary
35
- # number of children.
36
- #
37
- # A +Data+ object maintains the notion of the current sibling node
38
- # and a current parent node. Siblings are ordered within their parent.
39
- # Values are accessed and/or added by using the #next, #prev,
40
- # #enter, and #exit methods to navigate to the desired location in
41
- # the tree and using the supplied variety of mutator and accessor
42
- # methods to access or add a value of the desired type.
43
- #
44
- # The mutator methods will always add a value _after_ the current node
45
- # in the tree. If the current node has a next sibling the mutator method
46
- # will overwrite the value on this node. If there is no current node
47
- # or the current node has no next sibling then one will be added. The
48
- # accessor methods always set the added/modified node to the current
49
- # node. The accessor methods read the value of the current node and do
50
- # not change which node is current.
51
- #
52
- # The following types of scalar values are supported:
53
- #
54
- # * *NULL*
55
- # * *BOOL*
56
- # * *UBYTE*
57
- # * *BYTE*
58
- # * *USHORT*
59
- # * *SHORT*
60
- # * *UINT*
61
- # * *INT*
62
- # * *CHAR*
63
- # * *ULONG*
64
- # * *LONG*
65
- # * *TIMESTAMP*
66
- # * *FLOAT*
67
- # * *DOUBLE*
68
- # * *DECIMAL32*
69
- # * *DECIMAL64*
70
- # * *DECIMAL128*
71
- # * *UUID*
72
- # * *BINARY*
73
- # * *STRING*
74
- # * *SYMBOL*
75
- #
76
- # The following types of compound values are supported:
77
- #
78
- # * *DESCRIBED*
79
- # * *ARRAY*
80
- # * *LIST*
81
- # * *MAP*
82
- #
83
- class Data
84
-
85
- # Creates a new instance with the specified capacity.
86
- #
87
- # ==== Options
88
- #
89
- # * capacity - the capacity
90
- #
91
- def initialize(capacity = 16)
92
- if (!capacity.nil?) &&
93
- (capacity.is_a?(Fixnum) ||
94
- capacity.is_a?(Bignum))
95
- @data = Cproton.pn_data(capacity)
96
- @free = true
97
- else
98
- @data = capacity
99
- @free = false
100
- end
101
-
102
- # destructor
103
- ObjectSpace.define_finalizer(self, self.class.finalize!(@data))
104
- end
105
-
106
- def self.finalize!(data) # :nodoc:
107
- proc {
108
- Cproton.pn_data_free(data) if @free
109
- }
110
- end
111
-
112
- def to_s
113
- tmp = Cproton.pn_string("")
114
- Cproton.pn_inspect(@data, tmp)
115
- result = Cproton.pn_string_get(tmp)
116
- Cproton.pn_free(tmp)
117
- return result
118
- end
119
-
120
- # Clears the object.
121
- def clear
122
- Cproton.pn_data_clear(@data)
123
- end
124
-
125
- # Clears the current node and sets the parent to the root node.
126
- #
127
- # Clearing the current node sets it _before_ the first node, calling
128
- # #next will advance to the first node.
129
- def rewind
130
- Cproton.pn_data_rewind(@data)
131
- end
132
-
133
- # Advances the current node to its next sibling and returns its types.
134
- #
135
- # If there is no next sibling the current node remains unchanged
136
- # and nil is returned.
137
- def next(print = false)
138
- Cproton.pn_data_next(@data)
139
- end
140
-
141
- # Advances the current node to its previous sibling and returns its type.
142
- #
143
- # If there is no previous sibling then the current node remains unchanged
144
- # and nil is return.
145
- def prev
146
- return Cproton.pn_data_prev(@data) ? type : nil
147
- end
148
-
149
- # Sets the parent node to the current node and clears the current node.
150
- #
151
- # Clearing the current node sets it _before_ the first child.
152
- def enter
153
- Cproton.pn_data_enter(@data)
154
- end
155
-
156
- # Sets the current node to the parent node and the parent node to its own
157
- # parent.
158
- def exit
159
- Cproton.pn_data_exit(@data)
160
- end
161
-
162
- # Returns the numeric type code of the current node.
163
- def type_code
164
- dtype = Cproton.pn_data_type(@data)
165
- return (dtype == -1) ? nil : dtype
166
- end
167
-
168
- # Return the Type object for the current node
169
- def type
170
- Mapping.for_code(type_code)
171
- end
172
-
173
- # Returns a representation of the data encoded in AMQP format.
174
- def encode
175
- buffer = "\0"*1024
176
- loop do
177
- cd = Cproton.pn_data_encode(@data, buffer, buffer.length)
178
- if cd == Cproton::PN_OVERFLOW
179
- buffer *= 2
180
- elsif cd >= 0
181
- return buffer[0...cd]
182
- else
183
- check(cd)
184
- end
185
- end
186
- end
187
-
188
- # Decodes the first value from supplied AMQP data and returns the number
189
- # of bytes consumed.
190
- #
191
- # ==== Options
192
- #
193
- # * encoded - the encoded data
194
- #
195
- def decode(encoded)
196
- check(Cproton.pn_data_decode(@data, encoded, encoded.length))
197
- end
198
-
199
- # Puts a list value.
200
- #
201
- # Elements may be filled by entering the list node and putting element
202
- # values.
203
- #
204
- # ==== Examples
205
- #
206
- # data = Qpid::Proton::Data.new
207
- # data.put_list
208
- # data.enter
209
- # data.int = 1
210
- # data.int = 2
211
- # data.int = 3
212
- # data.exit
213
- #
214
- def put_list
215
- check(Cproton.pn_data_put_list(@data))
216
- end
217
-
218
- # If the current node is a list, this returns the number of elements.
219
- # Otherwise, it returns zero.
220
- #
221
- # List elements can be accessed by entering the list.
222
- #
223
- # ==== Examples
224
- #
225
- # count = @data.list
226
- # @data.enter
227
- # (0...count).each
228
- # type = @data.next
229
- # puts "Value: #{@data.string}" if type == STRING
230
- # # ... process other node types
231
- # end
232
- def list
233
- Cproton.pn_data_get_list(@data)
234
- end
235
-
236
- # Puts a map value.
237
- #
238
- # Elements may be filled by entering the map node and putting alternating
239
- # key/value pairs.
240
- #
241
- # ==== Examples
242
- #
243
- # data = Qpid::Proton::Data.new
244
- # data.put_map
245
- # data.enter
246
- # data.string = "key"
247
- # data.string = "value"
248
- # data.exit
249
- #
250
- def put_map
251
- check(Cproton.pn_data_put_map(@data))
252
- end
253
-
254
- # If the current node is a map, this returns the number of child
255
- # elements. Otherwise, it returns zero.
256
- #
257
- # Key/value pairs can be accessed by entering the map.
258
- #
259
- # ==== Examples
260
- #
261
- # count = @data.map
262
- # @data.enter
263
- # (0...count).each do
264
- # type = @data.next
265
- # puts "Key=#{@data.string}" if type == STRING
266
- # # ... process other key types
267
- # type = @data.next
268
- # puts "Value=#{@data.string}" if type == STRING
269
- # # ... process other value types
270
- # end
271
- # @data.exit
272
- def map
273
- Cproton.pn_data_get_map(@data)
274
- end
275
-
276
- def get_map # :nodoc:
277
- ::Hash.proton_data_get(self)
278
- end
279
-
280
- # Puts an array value.
281
- #
282
- # Elements may be filled by entering the array node and putting the
283
- # element values. The values must all be of the specified array element
284
- # type.
285
- #
286
- # If an array is *described* then the first child value of the array
287
- # is the descriptor and may be of any type.
288
- #
289
- # ==== Options
290
- #
291
- # * described - specifies whether the array is described
292
- # * element_type - the type of the array elements
293
- #
294
- # ==== Examples
295
- #
296
- # # create an array of integer values
297
- # data = Qpid::Proton::Data.new
298
- # data.put_array(false, INT)
299
- # data.enter
300
- # data.int = 1
301
- # data.int = 2
302
- # data.int = 3
303
- # data.exit
304
- #
305
- # # create an array of double values
306
- # data.put_array(true, DOUBLE)
307
- # data.enter
308
- # data.symbol = "array-descriptor"
309
- # data.double = 1.1
310
- # data.double = 1.2
311
- # data.double = 1.3
312
- # data.exit
313
- #
314
- def put_array(described, element_type)
315
- check(Cproton.pn_data_put_array(@data, described, element_type.code))
316
- end
317
-
318
- # If the current node is an array, returns a tuple of the element count, a
319
- # boolean indicating whether the array is described, and the type of each
320
- # element. Otherwise it returns +(0, false, nil).
321
- #
322
- # Array data can be accessed by entering the array.
323
- #
324
- # ==== Examples
325
- #
326
- # # get the details of thecurrent array
327
- # count, described, array_type = @data.array
328
- #
329
- # # enter the node
330
- # data.enter
331
- #
332
- # # get the next node
333
- # data.next
334
- # puts "Descriptor: #{data.symbol}" if described
335
- # (0...count).each do
336
- # @data.next
337
- # puts "Element: #{@data.string}"
338
- # end
339
- def array
340
- count = Cproton.pn_data_get_array(@data)
341
- described = Cproton.pn_data_is_array_described(@data)
342
- array_type = Cproton.pn_data_get_array_type(@data)
343
- return nil if array_type == -1
344
- [count, described, Mapping.for_code(array_type) ]
345
- end
346
-
347
- def get_array # :nodoc:
348
- ::Array.proton_get(self)
349
- end
350
-
351
- # Puts a described value.
352
- #
353
- # A described node has two children, the descriptor and the value.
354
- # These are specified by entering the node and putting the
355
- # desired values.
356
- #
357
- # ==== Examples
358
- #
359
- # data = Qpid::Proton::Data.new
360
- # data.put_described
361
- # data.enter
362
- # data.symbol = "value-descriptor"
363
- # data.string = "the value"
364
- # data.exit
365
- #
366
- def put_described
367
- check(Cproton.pn_data_put_described(@data))
368
- end
369
-
370
- def get_described # :nodoc:
371
- raise TypeError, "not a described type" unless self.described?
372
- self.enter
373
- self.next
374
- type = self.type
375
- descriptor = type.get(self)
376
- self.next
377
- type = self.type
378
- value = type.get(self)
379
- self.exit
380
- Described.new(descriptor, value)
381
- end
382
-
383
- # Checks if the current node is a described value.
384
- #
385
- # The described and value may be accessed by entering the described value.
386
- #
387
- # ==== Examples
388
- #
389
- # if @data.described?
390
- # @data.enter
391
- # puts "The symbol is #{@data.symbol}"
392
- # puts "The value is #{@data.string}"
393
- # end
394
- def described?
395
- Cproton.pn_data_is_described(@data)
396
- end
397
-
398
- # Puts a null value.
399
- def null
400
- check(Cproton.pn_data_put_null(@data))
401
- end
402
-
403
- # Utility method for Qpid::Proton::Mapping
404
- def null=(value) # :nodoc:
405
- null
406
- end
407
-
408
- # Checks if the current node is null.
409
- def null?
410
- Cproton.pn_data_is_null(@data)
411
- end
412
-
413
- # Puts a boolean value.
414
- #
415
- # ==== Options
416
- #
417
- # * value - the boolean value
418
- def bool=(value)
419
- check(Cproton.pn_data_put_bool(@data, value))
420
- end
421
-
422
- # If the current node is a boolean, then it returns the value. Otherwise,
423
- # it returns false.
424
- def bool
425
- Cproton.pn_data_get_bool(@data)
426
- end
427
-
428
- # Puts an unsigned byte value.
429
- #
430
- # ==== Options
431
- #
432
- # * value - the unsigned byte value
433
- def ubyte=(value)
434
- check(Cproton.pn_data_put_ubyte(@data, value))
435
- end
436
-
437
- # If the current node is an unsigned byte, returns its value. Otherwise,
438
- # it reutrns 0.
439
- def ubyte
440
- Cproton.pn_data_get_ubyte(@data)
441
- end
442
-
443
- # Puts a byte value.
444
- #
445
- # ==== Options
446
- #
447
- # * value - the byte value
448
- def byte=(value)
449
- check(Cproton.pn_data_put_byte(@data, value))
450
- end
451
-
452
- # If the current node is an byte, returns its value. Otherwise,
453
- # it returns 0.
454
- def byte
455
- Cproton.pn_data_get_byte(@data)
456
- end
457
-
458
- # Puts an unsigned short value.
459
- #
460
- # ==== Options
461
- #
462
- # * value - the unsigned short value
463
- def ushort=(value)
464
- check(Cproton.pn_data_put_ushort(@data, value))
465
- end
466
-
467
- # If the current node is an unsigned short, returns its value. Otherwise,
468
- # it returns 0.
469
- def ushort
470
- Cproton.pn_data_get_ushort(@data)
471
- end
472
-
473
- # Puts a short value.
474
- #
475
- # ==== Options
476
- #
477
- # * value - the short value
478
- def short=(value)
479
- check(Cproton.pn_data_put_short(@data, value))
480
- end
481
-
482
- # If the current node is a short, returns its value. Otherwise,
483
- # returns a 0.
484
- def short
485
- Cproton.pn_data_get_short(@data)
486
- end
487
-
488
- # Puts an unsigned integer value.
489
- #
490
- # ==== Options
491
- #
492
- # * value - the unsigned integer value
493
- def uint=(value)
494
- raise TypeError if value.nil?
495
- raise RangeError, "invalid uint: #{value}" if value < 0
496
- check(Cproton.pn_data_put_uint(@data, value))
497
- end
498
-
499
- # If the current node is an unsigned int, returns its value. Otherwise,
500
- # returns 0.
501
- def uint
502
- Cproton.pn_data_get_uint(@data)
503
- end
504
-
505
- # Puts an integer value.
506
- #
507
- # ==== Options
508
- #
509
- # * value - the integer value
510
- def int=(value)
511
- check(Cproton.pn_data_put_int(@data, value))
512
- end
513
-
514
- # If the current node is an integer, returns its value. Otherwise,
515
- # returns 0.
516
- def int
517
- Cproton.pn_data_get_int(@data)
518
- end
519
-
520
- # Puts a character value.
521
- #
522
- # ==== Options
523
- #
524
- # * value - the character value
525
- def char=(value)
526
- check(Cproton.pn_data_put_char(@data, value))
527
- end
528
-
529
- # If the current node is a character, returns its value. Otherwise,
530
- # returns 0.
531
- def char
532
- Cproton.pn_data_get_char(@data)
533
- end
534
-
535
- # Puts an unsigned long value.
536
- #
537
- # ==== Options
538
- #
539
- # * value - the unsigned long value
540
- def ulong=(value)
541
- raise TypeError if value.nil?
542
- raise RangeError, "invalid ulong: #{value}" if value < 0
543
- check(Cproton.pn_data_put_ulong(@data, value))
544
- end
545
-
546
- # If the current node is an unsigned long, returns its value. Otherwise,
547
- # returns 0.
548
- def ulong
549
- Cproton.pn_data_get_ulong(@data)
550
- end
551
-
552
- # Puts a long value.
553
- #
554
- # ==== Options
555
- #
556
- # * value - the long value
557
- def long=(value)
558
- check(Cproton.pn_data_put_long(@data, value))
559
- end
560
-
561
- # If the current node is a long, returns its value. Otherwise, returns 0.
562
- def long
563
- Cproton.pn_data_get_long(@data)
564
- end
565
-
566
- # Puts a timestamp value.
567
- #
568
- # ==== Options
569
- #
570
- # * value - the timestamp value
571
- def timestamp=(value)
572
- value = value.to_i if (!value.nil? && value.is_a?(Time))
573
- check(Cproton.pn_data_put_timestamp(@data, value))
574
- end
575
-
576
- # If the current node is a timestamp, returns its value. Otherwise,
577
- # returns 0.
578
- def timestamp
579
- Cproton.pn_data_get_timestamp(@data)
580
- end
581
-
582
- # Puts a float value.
583
- #
584
- # ==== Options
585
- #
586
- # * value - the float value
587
- def float=(value)
588
- check(Cproton.pn_data_put_float(@data, value))
589
- end
590
-
591
- # If the current node is a float, returns its value. Otherwise,
592
- # returns 0.
593
- def float
594
- Cproton.pn_data_get_float(@data)
595
- end
596
-
597
- # Puts a double value.
598
- #
599
- # ==== Options
600
- #
601
- # * value - the double value
602
- def double=(value)
603
- check(Cproton.pn_data_put_double(@data, value))
604
- end
605
-
606
- # If the current node is a double, returns its value. Otherwise,
607
- # returns 0.
608
- def double
609
- Cproton.pn_data_get_double(@data)
610
- end
611
-
612
- # Puts a decimal32 value.
613
- #
614
- # ==== Options
615
- #
616
- # * value - the decimal32 value
617
- def decimal32=(value)
618
- check(Cproton.pn_data_put_decimal32(@data, value))
619
- end
620
-
621
- # If the current node is a decimal32, returns its value. Otherwise,
622
- # returns 0.
623
- def decimal32
624
- Cproton.pn_data_get_decimal32(@data)
625
- end
626
-
627
- # Puts a decimal64 value.
628
- #
629
- # ==== Options
630
- #
631
- # * value - the decimal64 value
632
- def decimal64=(value)
633
- check(Cproton.pn_data_put_decimal64(@data, value))
634
- end
635
-
636
- # If the current node is a decimal64, returns its value. Otherwise,
637
- # it returns 0.
638
- def decimal64
639
- Cproton.pn_data_get_decimal64(@data)
640
- end
641
-
642
- # Puts a decimal128 value.
643
- #
644
- # ==== Options
645
- #
646
- # * value - the decimal128 value
647
- def decimal128=(value)
648
- raise TypeError, "invalid decimal128 value: #{value}" if value.nil?
649
- value = value.to_s(16).rjust(32, "0")
650
- bytes = []
651
- value.scan(/(..)/) {|v| bytes << v[0].to_i(16)}
652
- check(Cproton.pn_data_put_decimal128(@data, bytes))
653
- end
654
-
655
- # If the current node is a decimal128, returns its value. Otherwise,
656
- # returns 0.
657
- def decimal128
658
- value = ""
659
- Cproton.pn_data_get_decimal128(@data).each{|val| value += ("%02x" % val)}
660
- value.to_i(16)
661
- end
662
-
663
- # Puts a +UUID+ value.
664
- #
665
- # The UUID is expected to be in the format of a string or else a 128-bit
666
- # integer value.
667
- #
668
- # ==== Options
669
- #
670
- # * value - the +UUID+
671
- #
672
- # ==== Examples
673
- #
674
- # # set a uuid value from a string value
675
- # require 'securerandom'
676
- # @data.uuid = SecureRandom.uuid
677
- #
678
- # # or
679
- # @data.uuid = "fd0289a5-8eec-4a08-9283-81d02c9d2fff"
680
- #
681
- # # set a uuid value from a 128-bit value
682
- # @data.uuid = 0 # sets to 00000000-0000-0000-0000-000000000000
683
- #
684
- def uuid=(value)
685
- raise ArgumentError, "invalid uuid: #{value}" if value.nil?
686
-
687
- # if the uuid that was submitted was numeric value, then translated
688
- # it into a hex string, otherwise assume it was a string represtation
689
- # and attempt to decode it
690
- if value.is_a? Numeric
691
- value = "%032x" % value
692
- else
693
- raise ArgumentError, "invalid uuid: #{value}" if !valid_uuid?(value)
694
-
695
- value = (value[0, 8] +
696
- value[9, 4] +
697
- value[14, 4] +
698
- value[19, 4] +
699
- value[24, 12])
700
- end
701
- bytes = []
702
- value.scan(/(..)/) {|v| bytes << v[0].to_i(16)}
703
- check(Cproton.pn_data_put_uuid(@data, bytes))
704
- end
705
-
706
- # If the current value is a +UUID+, returns its value. Otherwise,
707
- # it returns nil.
708
- def uuid
709
- value = ""
710
- Cproton.pn_data_get_uuid(@data).each{|val| value += ("%02x" % val)}
711
- value.insert(8, "-").insert(13, "-").insert(18, "-").insert(23, "-")
712
- end
713
-
714
- # Puts a binary value.
715
- #
716
- # ==== Options
717
- #
718
- # * value - the binary value
719
- def binary=(value)
720
- check(Cproton.pn_data_put_binary(@data, value))
721
- end
722
-
723
- # If the current node is binary, returns its value. Otherwise, it returns
724
- # an empty string ("").
725
- def binary
726
- Qpid::Proton::BinaryString.new(Cproton.pn_data_get_binary(@data))
727
- end
728
-
729
- # Puts a unicode string value.
730
- #
731
- # *NOTE:* A nil value is stored as an empty string rather than as a nil.
732
- #
733
- # ==== Options
734
- #
735
- # * value - the unicode string value
736
- def string=(value)
737
- check(Cproton.pn_data_put_string(@data, value))
738
- end
739
-
740
- # If the current node is a string, returns its value. Otherwise, it
741
- # returns an empty string ("").
742
- def string
743
- Qpid::Proton::UTFString.new(Cproton.pn_data_get_string(@data))
744
- end
745
-
746
- # Puts a symbolic value.
747
- #
748
- # ==== Options
749
- #
750
- # * value - the symbol name
751
- def symbol=(value)
752
- check(Cproton.pn_data_put_symbol(@data, value))
753
- end
754
-
755
- # If the current node is a symbol, returns its value. Otherwise, it
756
- # returns an empty string ("").
757
- def symbol
758
- Cproton.pn_data_get_symbol(@data)
759
- end
760
-
761
- # Get the current value as a single object.
762
- def get
763
- type.get(self);
764
- end
765
-
766
- # Put value as an object of type type_
767
- def put(value, type_);
768
- type_.put(self, value);
769
- end
770
-
771
- private
772
-
773
- def valid_uuid?(value)
774
- # ensure that the UUID is in the right format
775
- # xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
776
- 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}/
777
- end
778
-
779
- def check(err) # :nodoc:
780
- if err < 0
781
- raise DataError, "[#{err}]: #{Cproton.pn_data_error(@data)}"
782
- else
783
- return err
784
- end
785
- end
786
- end
787
- end
788
- end