Class: Bytepack::FixedSize
- Defined in:
- lib/bytepack/basic/fixed_size.rb
Direct Known Subclasses
Class Method Summary collapse
Methods inherited from Basic
bytesToInt, intToBytes, preprocess
Methods inherited from Struct
classifyDataType, config, packingDataType, single_type_array?, testpacking
Class Method Details
.pack(val) ⇒ Object
5 6 7 8 |
# File 'lib/bytepack/basic/fixed_size.rb', line 5 def pack(val) val ||= self::NULL_INDICATOR [val].pack(self::DIRECTIVE) end |
.unpack(bytes, offset = 0) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/bytepack/basic/fixed_size.rb', line 10 def unpack(bytes, offset = 0) offset, format = *preprocess(bytes, offset, self::DIRECTIVE, self::LENGTH) unpacked = bytes.unpack1(format) if unpacked == self::NULL_INDICATOR [nil, offset] else [unpacked, offset] end end |