On Saturday, November 22, 2014 10:06:24 PM UTC-6, Joshua Adelman wrote:
>
> I just checked out StrPack and installed it. I think I have it working
> properly in the case of a packed immutable type that just contains
> numerical fields. I'm still not sure how to make things work to unpack
> fixed length strings.
>
That's the least-tested codepath, I think.
> If my string in field "e" is a fixed-length of 4, then my composite type
> looks like
>
> @struct immutable TestType2
> a::Float64
> b::Int32
> c::Float32
> d::Int16
> e::Array{Uint8,1}(4) # also tried ASCIIString(4)
> end
>
That looks correct. Though I'm not sure where you would get pad bytes in
here? Alignments all look native.
And then I know my data on file has 10 records, I can loop through as:
>
> data = Array(TestType2, (10,))
>
> f = open("test1.dat", "r")
> for k = 1:10
> data[k] = unpack(f, TestType2, {"a"=>8, "b"=>4,"c"=>4, "d"=>2,
> "e"=>4}, align_packed, :NativeEndian)
> println(data[k])
> end
>
> But Array{Uint8,1}(4) results in corrupted values after the first record
> is read in and ASCIIString(4) gives an error:
>
> TestType2(-1.2538434657806456,0,0.5783242f0,0,"a")
> ERROR: invalid ASCII sequence
>
What is the binary data you're reading? Is there a sample file?
Where in the first record that appears to be read correctly (at least it
> prints), the last field value should be "abcd" not "a". Am I missing
> something obvious? Also, is there a strategy for combining all of this with
> a memory mapped file?
>
Probably. If you can get a stream, you can unpack it. You might need some
combination of mmap_array() and IOBuffer().