Class: OSC::NetworkPacket
- Inherits:
-
Object
- Object
- OSC::NetworkPacket
- Defined in:
- lib/osc-ruby/network_packet.rb
Instance Method Summary collapse
- #eof? ⇒ Boolean
- #getc ⇒ Object
- #getn(n) ⇒ Object
-
#initialize(str) ⇒ NetworkPacket
constructor
A new instance of NetworkPacket.
- #rem ⇒ Object
- #skip(n) ⇒ Object
- #skip_padding ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(str) ⇒ NetworkPacket
Returns a new instance of NetworkPacket.
3 4 5 6 |
# File 'lib/osc-ruby/network_packet.rb', line 3 def initialize(str) @str = str.force_encoding("BINARY") @index = 0 end |
Instance Method Details
#eof? ⇒ Boolean
16 17 18 |
# File 'lib/osc-ruby/network_packet.rb', line 16 def eof? rem <= 0 end |
#getc ⇒ Object
35 36 37 38 39 40 |
# File 'lib/osc-ruby/network_packet.rb', line 35 def getc raise(EOFError) if rem < 1 c = @str[@index] skip(1) c end |
#getn(n) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/osc-ruby/network_packet.rb', line 28 def getn(n) raise(EOFError) if rem < n s = @str[@index, n] skip(n) s end |
#rem ⇒ Object
12 13 14 |
# File 'lib/osc-ruby/network_packet.rb', line 12 def rem @str.length - @index end |
#skip(n) ⇒ Object
20 21 22 |
# File 'lib/osc-ruby/network_packet.rb', line 20 def skip(n) @index += n end |
#skip_padding ⇒ Object
24 25 26 |
# File 'lib/osc-ruby/network_packet.rb', line 24 def skip_padding skip((4 - (@index % 4)) % 4) end |
#to_s ⇒ Object
8 9 10 |
# File 'lib/osc-ruby/network_packet.rb', line 8 def to_s @str end |