Class: GameMachine::MessageBuffer
- Inherits:
-
Object
- Object
- GameMachine::MessageBuffer
- Defined in:
- lib/game_machine/message_buffer.rb
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
-
#next_message_length ⇒ Object
readonly
Returns the value of attribute next_message_length.
Instance Method Summary collapse
- #add_bytes(bytes_to_add) ⇒ Object
-
#initialize ⇒ MessageBuffer
constructor
A new instance of MessageBuffer.
- #messages ⇒ Object
Constructor Details
#initialize ⇒ MessageBuffer
Returns a new instance of MessageBuffer.
5 6 7 |
# File 'lib/game_machine/message_buffer.rb', line 5 def initialize reset end |
Instance Attribute Details
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
4 5 6 |
# File 'lib/game_machine/message_buffer.rb', line 4 def bytes @bytes end |
#next_message_length ⇒ Object (readonly)
Returns the value of attribute next_message_length.
4 5 6 |
# File 'lib/game_machine/message_buffer.rb', line 4 def @next_message_length end |
Instance Method Details
#add_bytes(bytes_to_add) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/game_machine/message_buffer.rb', line 33 def add_bytes(bytes_to_add) if @bytes.nil? @bytes = bytes_to_add else new_bytes = Java::byte[bytes_to_add.length + @bytes.length].new java.lang.System.arraycopy(@bytes, 0, new_bytes, 0, @bytes.length) java.lang.System.arraycopy(bytes_to_add, 0, new_bytes, @bytes.length, bytes_to_add.length) @bytes = new_bytes end end |
#messages ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/game_machine/message_buffer.rb', line 9 def = [] return if bytes.nil? stream = JavaLib::ByteArrayInputStream.new(bytes) if == 0 @next_message_length = (stream) end while >= 1 && stream.available >= = Java::byte[].new stream.read(,0,) << if stream.available >= 1 @next_message_length = (stream) if > stream.available @bytes = Java::byte[stream.available].new stream.read(@bytes,0,stream.available) end else reset end end end |