Module: ElfUtils::Types::UnitLength Private
- Extended by:
- CTypes::Type
- Defined in:
- lib/elf_utils/types/unit_length.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Class Method Summary collapse
- .fixed_size? ⇒ Boolean private
-
.pack(value, endian: default_endian, validate: true) ⇒ Object
private
provide a method for packing the ruby value into the binary representation.
- .size ⇒ Object private
-
.unpack_one(buf, endian: default_endian) ⇒ Object
private
provide a method for unpacking an instance of this type from a String, and returning both the unpacked value, and any unused input.
Class Method Details
.fixed_size? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/elf_utils/types/unit_length.rb', line 16 def self.fixed_size? false end |
.pack(value, endian: default_endian, validate: true) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
provide a method for packing the ruby value into the binary representation
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/elf_utils/types/unit_length.rb', line 25 def self.pack(value, endian: default_endian, validate: true) return "\0" if value == 0 buf = +"" while value != 0 byte = (value & 0x7f) value >>= 7 byte |= 0x80 if value != 0 buf << byte end buf end |
.size ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/elf_utils/types/unit_length.rb', line 20 def self.size @size end |
.unpack_one(buf, endian: default_endian) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
provide a method for unpacking an instance of this type from a String, and returning both the unpacked value, and any unused input
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/elf_utils/types/unit_length.rb', line 39 def self.unpack_one(buf, endian: default_endian) value = 0 shift = 0 len = 0 buf.each_byte do |b| len += 1 value |= ((b & 0x7f) << shift) return value, buf.byteslice(len...) if (b & 0x80) == 0 shift += 7 end raise TerminatorNotFoundError end |