Module: LVM::Helpers

Included in:
Snapshot
Defined in:
lib/lvm/helpers.rb

Instance Method Summary collapse

Instance Method Details

#big_endian?Boolean

Are we on a big-endian system? Needed for our htonq/ntohq methods

Returns:

  • (Boolean)


5
6
7
# File 'lib/lvm/helpers.rb', line 5

def big_endian?
	@bigendian ||= [1].pack("s") == [1].pack("n")
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].pack("Q").reverse.unpack("Q").first) : val
end

#ntohq(val) ⇒ Object



15
16
17
# File 'lib/lvm/helpers.rb', line 15

def ntohq val
	htonq val
end