Class: OSC::Bundle
- Inherits:
-
Array
- Object
- Array
- OSC::Bundle
- Defined in:
- lib/ruby-osc/bundle.rb
Instance Attribute Summary collapse
-
#timetag ⇒ Object
Returns the value of attribute timetag.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #encode ⇒ Object
-
#initialize(timetag = nil, *args) ⇒ Bundle
constructor
A new instance of Bundle.
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(timetag = nil, *args) ⇒ Bundle
Returns a new instance of Bundle.
5 6 7 8 9 10 |
# File 'lib/ruby-osc/bundle.rb', line 5 def initialize = nil, *args args.each{ |arg| raise TypeError, "#{ arg.inspect } is required to be a Bundle or Message" unless Bundle === arg or Message === arg } raise TypeError, "#{ .inspect } is required to be Time or nil" unless == nil or Time === super args @timetag = end |
Instance Attribute Details
#timetag ⇒ Object
Returns the value of attribute timetag.
3 4 5 |
# File 'lib/ruby-osc/bundle.rb', line 3 def @timetag end |
Class Method Details
.decode(string) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby-osc/bundle.rb', line 25 def self.decode string string.sub! /^#bundle\000/, '' t1, t2, content_str = string.unpack('N2a*') = t1 == 0 && t2 == 1 ? nil : Time.at(t1 + t2 / (2**32.0) - 2_208_988_800) scanner = StringScanner.new content_str args = [] until scanner.eos? size = scanner.scan(/.{4}/).unpack('N').first arg_str = scanner.scan(/.{#{ size }}/nm) rescue raise(DecodeError, "An error occured while trying to decode bad formatted osc bundle") args << OSC.decode(arg_str) end new , *args end |
Instance Method Details
#==(other) ⇒ Object
42 43 44 |
# File 'lib/ruby-osc/bundle.rb', line 42 def == other self.class == other.class and self. == other. and self.to_a == other.to_a end |
#encode ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ruby-osc/bundle.rb', line 12 def encode = if @timetag time, tag, dir = OSC.encoding_directive @timetag time.pack dir else "\000\000\000\000\000\000\000\001" end "#bundle\000#{ }" + collect do |x| x = x.encode [x.size].pack('N') + x end.join end |
#to_a ⇒ Object
46 |
# File 'lib/ruby-osc/bundle.rb', line 46 def to_a; Array.new self; end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/ruby-osc/bundle.rb', line 48 def to_s "OSC::Bundle(#{ self.join(', ') })" end |