April 12, 2009
I want to create a struct like this:
struct test
{  int  item 1;
   int  item 2;
   int  dataLen;
   ubyte[]  data;
}

Then I want to read & write the structure using readExact and writeExact.  Can I do this (somehow?) or do I need to do the reads/writes separately for each piece?

I'm sure I could just declare data large enough to hold all cases, but that gets wasteful over time.  I could just use a buffered file, so that doing the reads/writes separately would be cheaper.  But if I'm using an ordinary file is there a way to do this using readexact/writeexact? (I.e., if I wrote/read the proper number of bytes, would I get the correct data, and is the proper number == 3*int.sizeof + data.length?)

I feel like I could write lots of tests, but each one would just prove "That's not the way to do it".