Class: Thermal::ByteBuffer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/thermal/byte_buffer.rb

Instance Method Summary collapse

Instance Method Details

#<<(obj) ⇒ Object Also known as: write, sequence



11
12
13
14
15
16
17
18
# File 'lib/thermal/byte_buffer.rb', line 11

def <<(obj)
  case obj
  when String then append(*obj.bytes)
  when Integer then append(obj)
  when Array then append(*obj)
  else raise "Unknown object type: #{obj.class}"
  end
end

#bufferObject



7
8
9
# File 'lib/thermal/byte_buffer.rb', line 7

def buffer
  @buffer ||= []
end

#flushObject



34
35
36
37
38
# File 'lib/thermal/byte_buffer.rb', line 34

def flush
  tmp = buffer
  @buffer = nil
  tmp
end

#flush_base64Object



40
41
42
43
44
# File 'lib/thermal/byte_buffer.rb', line 40

def flush_base64
  tmp = to_base64
  flush
  tmp
end

#to_aObject



30
31
32
# File 'lib/thermal/byte_buffer.rb', line 30

def to_a
  buffer.dup
end

#to_base64Object



22
23
24
# File 'lib/thermal/byte_buffer.rb', line 22

def to_base64
  Base64.strict_encode64(to_s)
end

#to_sObject



26
27
28
# File 'lib/thermal/byte_buffer.rb', line 26

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