Class: OSC::NetworkPacket

Inherits:
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
# File 'lib/osc-ruby/network_packet.rb', line 3

def initialize(str) 
  @str, @index = str, 0 
end

Instance Method Details

#eof?Boolean

Returns:

  • (Boolean)


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

def eof? () 
  rem <= 0 
end

#getcObject

Raises:

  • (EOFError)


34
35
36
37
38
39
# File 'lib/osc-ruby/network_packet.rb', line 34

def getc
	raise EOFError if rem < 1
	c = @str[@index]
	skip(1)
	c
end

#getn(n) ⇒ Object

Raises:

  • (EOFError)


27
28
29
30
31
32
# File 'lib/osc-ruby/network_packet.rb', line 27

def getn(n)
	raise EOFError if rem < n
	s = @str[@index, n]
	skip(n)
	s
end

#remObject



11
12
13
# File 'lib/osc-ruby/network_packet.rb', line 11

def rem() 
  @str.length - @index 
end

#skip(n) ⇒ Object



19
20
21
# File 'lib/osc-ruby/network_packet.rb', line 19

def skip(n) 
  @index += n 
end

#skip_paddingObject



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

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

#to_sObject



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

def to_s
  @str
end