Class: Coder::Cleaner::Simple::ByteBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/coder/cleaner/simple/byte_buffer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(encoding) ⇒ ByteBuffer

Returns a new instance of ByteBuffer.



7
8
9
10
# File 'lib/coder/cleaner/simple/byte_buffer.rb', line 7

def initialize(encoding)
  @encoding, @bytes = encoding, []
  clear_buffer
end

Instance Attribute Details

#bufferObject

Returns the value of attribute buffer.



5
6
7
# File 'lib/coder/cleaner/simple/byte_buffer.rb', line 5

def buffer
  @buffer
end

#bytesObject

Returns the value of attribute bytes.



5
6
7
# File 'lib/coder/cleaner/simple/byte_buffer.rb', line 5

def bytes
  @bytes
end

#encodingObject

Returns the value of attribute encoding.



5
6
7
# File 'lib/coder/cleaner/simple/byte_buffer.rb', line 5

def encoding
  @encoding
end

#outstandingObject

Returns the value of attribute outstanding.



5
6
7
# File 'lib/coder/cleaner/simple/byte_buffer.rb', line 5

def outstanding
  @outstanding
end

Instance Method Details

#<<(byte) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/coder/cleaner/simple/byte_buffer.rb', line 12

def <<(byte)
  if encoding.garbage? byte, buffer
    clear_buffer
  elsif encoding.single_byte? byte, buffer
    add(byte)
  elsif encoding.multibyte_body? byte, buffer
    fill_buffer(byte)
  elsif encoding.multibyte_start? byte, buffer
    start_buffer(byte, encoding.multibyte_size(byte, buffer))
  else
    clear_buffer
  end
end

#to_sObject



26
27
28
# File 'lib/coder/cleaner/simple/byte_buffer.rb', line 26

def to_s
  bytes.pack('C*')
end