Module: LVM::Helpers
- Included in:
- Snapshot
- Defined in:
- lib/lvm/helpers.rb
Instance Method Summary collapse
-
#big_endian? ⇒ Boolean
Are we on a big-endian system? Needed for our htonq/ntohq methods.
-
#dtohq(val) ⇒ Object
On-disk (LVM) format (which is little-endian) to host byte order.
- #htonq(val) ⇒ Object
- #ntohq(val) ⇒ Object
- #swap_longs(val) ⇒ Object
Instance Method Details
#big_endian? ⇒ Boolean
Are we on a big-endian system? Needed for our htonq/ntohq methods
5 6 7 |
# File 'lib/lvm/helpers.rb', line 5 def big_endian? @big_endian ||= [1].pack("s") == [1].pack("n") end |
#dtohq(val) ⇒ Object
On-disk (LVM) format (which is little-endian) to host byte order
20 21 22 |
# File 'lib/lvm/helpers.rb', line 20 def dtohq val big_endian? ? swap_longs(val) : val end |
#htonq(val) ⇒ Object
9 10 11 12 13 |
# File 'lib/lvm/helpers.rb', line 9 def htonq val # This won't work on a nUxi byte-order machine, but if you have one of # those, I'm guessing you've got bigger problems big_endian? ? val : swap_longs(val) end |
#ntohq(val) ⇒ Object
15 16 17 |
# File 'lib/lvm/helpers.rb', line 15 def ntohq val big_endian? ? val : swap_longs(val) end |
#swap_longs(val) ⇒ Object
24 25 26 |
# File 'lib/lvm/helpers.rb', line 24 def swap_longs val [val].pack("Q").reverse.unpack("Q").first end |