Class: OSC::NetworkPacket

Inherits:
Object
  • Object
show all
Defined in:
lib/osc-ruby/network_packet.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


16
17
18
# File 'lib/osc-ruby/network_packet.rb', line 16

def eof?
  rem <= 0
end

#getcObject

Raises:

  • (EOFError)


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

Raises:

  • (EOFError)


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

#remObject



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_paddingObject



24
25
26
# File 'lib/osc-ruby/network_packet.rb', line 24

def skip_padding
  skip((4 - (@index % 4)) % 4)
end

#to_sObject



8
9
10
# File 'lib/osc-ruby/network_packet.rb', line 8

def to_s
  @str
end