Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Commit

Permalink
Add some utility functions for reading big-endian and little-endian d…
Browse files Browse the repository at this point in the history
…ata.
  • Loading branch information
Daniel Wyatt authored and Daniel Wyatt committed Dec 21, 2016
1 parent 76ba4f9 commit f3297b0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/read_utils.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def read8(io)
io.read(1).unpack('C')[0]
end

def read16le(io)
io.read(2).unpack('S<')[0]
end

def read16be(io)
io.read(2).unpack('S>')[0]
end

def read32le(io)
io.read(4).unpack('L<')[0]
end

def read32be(io)
io.read(4).unpack('L>')[0]
end

def read64le(io)
io.read(8).unpack('Q<')[0]
end

def read64be(io)
io.read(8).unpack('Q>')[0]
end

0 comments on commit f3297b0

Please sign in to comment.