Reading binary struct

B

Blmn

Hello
how can i creat e structure and read the struct from a binary file?
binaryreader doesn't accept objects so i have to read like reader.getbyte(),
reader.getint32(),... . but it should be a way to create a class líke
FileHeader and read compelet header at once, like C++ .
do you know how?
 
A

Andriy Gnennyy

Hello,

Use binary serialization.
Mark your structure as [Serializable] and use the
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter class.
 
B

Blmn

not possible.
seialization only works when the file being created by serialization. then
they can be deserialized. it can't apply to ordinary files.
actually i don't create these files, i just read'em. the program that create
these files is uder unix and works from 1989. can't even dream about
changing that program.


Andriy Gnennyy said:
Hello,

Use binary serialization.
Mark your structure as [Serializable] and use the
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter class.

--
Andriy Gnennyy
pulsar2003@{no-spam}email.ru (Please remove {no-spam} for reply)
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx

Blmn said:
Hello
how can i creat e structure and read the struct from a binary file?
binaryreader doesn't accept objects so i have to read like reader.getbyte(),
reader.getint32(),... . but it should be a way to create a class líke
FileHeader and read compelet header at once, like C++ .
do you know how?
 
H

Hemraj Julha

Blmn

How about identifying the byte size of your structure, reading a chink of
bytes using ReadBytes ( I hope this method exists) and then mapping to the
fields in your structure?

Cheers

Raj
 
S

Sijin Joseph

N

Nick Malik

Actually, when you mark an object as serializable and then write it using
the binary formatter, it doesn't put "special" markings stating the object
type. It just writes the data. If you want to, you can read the data from
the data file into a byte array, rearrange the bytes to match the
expectations of the deserializer, create a memory stream from your modified
byte array, and deserialize to the object from the stream.

Honestly, I wouldn't think it to be worth doing, but that's your call.

--- Nick

Blmn said:
not possible.
seialization only works when the file being created by serialization. then
they can be deserialized. it can't apply to ordinary files.
actually i don't create these files, i just read'em. the program that create
these files is uder unix and works from 1989. can't even dream about
changing that program.


Andriy Gnennyy said:
Hello,

Use binary serialization.
Mark your structure as [Serializable] and use the
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter class.

--
Andriy Gnennyy
pulsar2003@{no-spam}email.ru (Please remove {no-spam} for reply)
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx

Blmn said:
Hello
how can i creat e structure and read the struct from a binary file?
binaryreader doesn't accept objects so i have to read like reader.getbyte(),
reader.getint32(),... . but it should be a way to create a class líke
FileHeader and read compelet header at once, like C++ .
do you know how?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top