Suppose your format is:
struct Format { struct Header // 1 { byte a; bool b1, b2, b3, b4, b5, b6, b7, b8; string name; } struct Container // 1...* { MyTypeEnum Type; byte[] data; } } enum MyTypeEnum { Sound, Video, Image }
Then I will have a file with the sequence:
byte // a
byte // b
int // name size
char [] // name (which has the above size, remember that char is 16 bits in .NET)
int // type MyTypeEnum
int // data size
byte [] // data (the size of which is indicated above)
Then you can repeat the last three lines as much as you want.
For reading, use BinaryReader , which supports reading bytes, integers, and series of bytes. There is also a BinaryWriter .
Also, remember that Microsoft.NET (thus, on a Windows / Intel-based computer) is hardly accepted. Similarly, BinaryReader and BinaryWriter .
tofi9 source share