class Reactomatic::Buffer

Attributes

max_length[R]

Public Class Methods

new(opts = {}) click to toggle source
# File lib/reactomatic/buffer.rb, line 5
def initialize(opts = {})
  @max_length = opts[:max_length]
  @opts = opts
  @lock = Mutex.new
  @buffer = ""
end

Public Instance Methods

append(data) click to toggle source
# File lib/reactomatic/buffer.rb, line 12
def append(data)
  if @max_length.nil? || length + data.bytesize <= @max_length
    @buffer.concat(data)
  else
    raise BufferFull
  end
end
consume(length) click to toggle source
# File lib/reactomatic/buffer.rb, line 24
def consume(length)
  return @buffer.slice!(0...length)
end
empty?() click to toggle source
# File lib/reactomatic/buffer.rb, line 37
def empty?
  return @buffer.empty?
end
full?() click to toggle source
# File lib/reactomatic/buffer.rb, line 32
def full?
  return false if @max_length.nil?
  return @buffer.bytesize >= @max_length
end
length() click to toggle source
# File lib/reactomatic/buffer.rb, line 28
def length
  return @buffer.bytesize
end
read() click to toggle source
# File lib/reactomatic/buffer.rb, line 20
def read
  return @buffer
end