class BinData::Uint8Array
Uint8Array
is a specialised type of array that only contains bytes (Uint8
). It is a faster and more memory efficient version of `BinData::Array.new(:type => :uint8)`.
require 'bindata' obj = BinData::Uint8Array.new(initial_length: 5) obj.read("abcdefg") #=> [97, 98, 99, 100, 101] obj[2] #=> 99 obj.collect { |x| x.chr }.join #=> "abcde"
Parameters¶ ↑
Parameters may be provided at initialisation to control the behaviour of an object. These params are:
:initial_length
-
The initial length of the array.
:read_until
-
May only have a value of `:eof`. This parameter instructs the array to read as much data from the stream as possible.
Private Instance Methods
read_and_return_value(io)
click to toggle source
# File lib/bindata/uint8_array.rb, line 36 def read_and_return_value(io) if has_parameter?(:initial_length) data = io.readbytes(eval_parameter(:initial_length)) else data = io.read_all_bytes end data.unpack("C*") end
sensible_default()
click to toggle source
# File lib/bindata/uint8_array.rb, line 46 def sensible_default [] end
value_to_binary_string(val)
click to toggle source
# File lib/bindata/uint8_array.rb, line 32 def value_to_binary_string(val) val.pack("C*") end