Method: CTypes::Type#pread

Defined in:
lib/ctypes/type.rb

#pread(io, pos, endian: default_endian) ⇒ Object

read a fixed-sized type from an IO instance at a specific offset and unpack it

Parameters:

  • buf (::String)

    bytes that make up the type

  • pos (::Integer)

    seek position

  • endian (Symbol) (defaults to: default_endian)

    endian of data within buf

Returns:

  • decoded type



107
108
109
110
111
112
113
114
# File 'lib/ctypes/type.rb', line 107

def pread(io, pos, endian: default_endian)
  unless fixed_size?
    raise NotImplementedError,
      "pread() does not support variable-length types"
  end

  unpack(io.pread(@size, pos), endian: default_endian)
end