class Aws::EventStream::BytesBuffer

@api private

Public Class Methods

new(data) click to toggle source

This Util class is for Decoder/Encoder usage only Not for public common bytes buffer usage

# File lib/aws-eventstream/bytes_buffer.rb, line 9
def initialize(data)
  @data = data
  @pos = 0
end

Public Instance Methods

<<(bytes)
Alias for: write
bytesize() click to toggle source
# File lib/aws-eventstream/bytes_buffer.rb, line 51
def bytesize
  @data.bytesize
end
clear!() click to toggle source
# File lib/aws-eventstream/bytes_buffer.rb, line 59
def clear!
  @data = ''
  @pos = 0
end
eof?() click to toggle source
# File lib/aws-eventstream/bytes_buffer.rb, line 47
def eof?
  @pos == bytesize
end
read(len = nil, offset = 0) click to toggle source
# File lib/aws-eventstream/bytes_buffer.rb, line 14
def read(len = nil, offset = 0)
  return '' if len == 0 || bytesize == 0
  unless eof?
    start_byte = @pos + offset
    end_byte = len ?
      start_byte + len - 1 :
      bytesize - 1

    error = Errors::ReadBytesExceedLengthError.new(end_byte, bytesize)
    raise error if end_byte >= bytesize

    @pos = end_byte + 1
    @data[start_byte..end_byte]
  end
end
readbyte() click to toggle source
# File lib/aws-eventstream/bytes_buffer.rb, line 30
def readbyte
  unless eof?
    @pos += 1
    @data[@pos - 1]
  end
end
rewind() click to toggle source
# File lib/aws-eventstream/bytes_buffer.rb, line 43
def rewind
  @pos = 0
end
tell() click to toggle source
# File lib/aws-eventstream/bytes_buffer.rb, line 55
def tell
  @pos
end
write(bytes) click to toggle source
# File lib/aws-eventstream/bytes_buffer.rb, line 37
def write(bytes)
  @data <<= bytes
  bytes.bytesize
end
Also aliased as: <<