Skip to content

Absolute reads

Jacob edited this page Aug 25, 2016 · 2 revisions

These methods read a type at the given index but don't increment the buffer's position and are not affected by its limit. They raise IndexError if the index is out of bounds or if there's not enough bytes between index and capacity to read a type of that size.

bb = ByteBuffer.new(12)
bb.write [123, 456, 789]
bb.read 8, Int32 # => 789
bb.read 0, Int32 # => 123
bb.read 4, Int32 # => 456
bb.read 9, Int32 # => Index out of bounds (IndexError)
method description
read(index : Int) Reads a UInt8 at index
read(index : Int, t : Int8.class) Reads an Int8 at index
read(index : Int, t : UInt8.class) Reads a UInt8 at index, like read(index)
read(index : Int, t : Int16.class) Reads an Int16 at index
read(index : Int, t : UInt16.class) Reads a UInt16 at index
read(index : Int, t : Int32.class) Reads an Int32 at index
read(index : Int, t : UInt32.class) Reads a UInt32 at index
read(index : Int, t : Int64.class) Reads an Int64 at index
read(index : Int, t : UInt64.class) Reads a UInt64 at index
read(index : Int, t : Float32.class) Reads a Float32 at index
read(index : Int, t : Float64.class) Reads a Float64 at index
Clone this wiki locally