Method: CTypes::Bitfield.unpack_one
- Defined in:
- lib/ctypes/bitfield.rb
.unpack_one(buf, endian: default_endian) ⇒ Bitfield
convert a String containing the binary represention of a c type into the equivalent ruby type
131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/ctypes/bitfield.rb', line 131 def self.unpack_one(buf, endian: default_endian) value, rest = @type.unpack_one(buf, endian:) out = _new @bits.each do |(name, offset, mask, signed, var)| v = (value >> offset) & mask v |= (-1 << signed) | v if signed && v[signed - 1] == 1 out.instance_variable_set(var, v) end [out, rest] end |