Last active
August 29, 2015 14:11
-
-
Save twadleigh/7c08ef7bac671604ebeb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# init file with test data: bytes of 0, 1, 2, .. | |
fn = "tmp.dat" | |
open(fn, "w") do s | |
write(s, UInt8[i-1 for i in 1:256]) | |
end | |
import Base.read | |
# define an immutable type and a read | |
immutable A | |
a :: UInt32 | |
b :: UInt16 | |
end | |
function read(s::IO, ::Type{A}) | |
a = ntoh(read(s, UInt32)) | |
b = ntoh(read(s, UInt16)) | |
A(a, b) | |
end | |
print("sizeof A: ", sizeof(A), "\n") | |
# test read footprint | |
open(fn, "r") do s | |
seekstart(s) | |
a1 = read(s, A) | |
p1 = position(s) | |
print(a1, "\n") | |
print("Bytes read for single value: ", p1, "\n") | |
seekstart(s) | |
a2 = read(s, A, 1) | |
p2 = position(s) | |
print(a2, "\n") | |
print("Bytes read per value for array: ", p2, "\n") | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment