class Hiredis::Ruby::Reader::Buffer

Constants

CRLF

Public Class Methods

new() click to toggle source
# File lib/hiredis/ruby/reader.rb, line 116
def initialize
  @buffer = ""
  @length = @pos = 0
end

Public Instance Methods

<<(data) click to toggle source
# File lib/hiredis/ruby/reader.rb, line 121
def <<(data)
  @length += data.length
  @buffer << data
end
discard!() click to toggle source
# File lib/hiredis/ruby/reader.rb, line 134
def discard!
  if @length == 0
    @buffer = ""
    @length = @pos = 0
  else
    if @pos >= 1024
      @buffer.slice!(0, @pos)
      @length -= @pos
      @pos = 0
    end
  end
end
empty?() click to toggle source
# File lib/hiredis/ruby/reader.rb, line 130
def empty?
  @length == 0
end
length() click to toggle source
# File lib/hiredis/ruby/reader.rb, line 126
def length
  @length
end
read(bytes, skip = 0) click to toggle source
# File lib/hiredis/ruby/reader.rb, line 147
def read(bytes, skip = 0)
  start = @pos
  stop = start + bytes + skip
  return false if @length < stop

  @pos = stop
  force_encoding @buffer[start, bytes]
end
read_line() click to toggle source
# File lib/hiredis/ruby/reader.rb, line 156
def read_line
  start = @pos
  stop = @buffer.index(CRLF, @pos)
  return false unless stop

  @pos = stop + 2 # include CRLF
  force_encoding @buffer[start, stop - start]
end

Private Instance Methods

force_encoding(str) click to toggle source
# File lib/hiredis/ruby/reader.rb, line 169
def force_encoding(str)
  str.force_encoding(Encoding.default_external)
end