M
Marquee
Hello,
This is my first program c#, my background is c++. One thing I would
like to do is put binary data (e.g. a record from disk, or network
packet) in a struct. In C++ I would create the struct and memcpy() the
data into it thus creating a structured overlay. The struct can have
variable length e.g.
struct CRecord //Just for example
{
int m_iLength;
int m_iType;
string m_Whatever; //C++ would be like char m_Whatever[10];
byte[] m_AnyData; //Variable length field.
};
I thried this in c# with MemoryStream and BinaryFormatter, but these
methods put some .NET specific medata data into the stream. Is there a
managed way to do accomplish this?
C++ equivalent:
CRecord *NewRecord( unsigned char *pData, int cbData )
{
//Data validation here
CRecord *pRec = (CRecord*) new char( cbData );
memcpy( pRec, pData, cbData );
return( pRec);
}
Can somebody help to point out a direction/solution.
Thanx!
This is my first program c#, my background is c++. One thing I would
like to do is put binary data (e.g. a record from disk, or network
packet) in a struct. In C++ I would create the struct and memcpy() the
data into it thus creating a structured overlay. The struct can have
variable length e.g.
struct CRecord //Just for example
{
int m_iLength;
int m_iType;
string m_Whatever; //C++ would be like char m_Whatever[10];
byte[] m_AnyData; //Variable length field.
};
I thried this in c# with MemoryStream and BinaryFormatter, but these
methods put some .NET specific medata data into the stream. Is there a
managed way to do accomplish this?
C++ equivalent:
CRecord *NewRecord( unsigned char *pData, int cbData )
{
//Data validation here
CRecord *pRec = (CRecord*) new char( cbData );
memcpy( pRec, pData, cbData );
return( pRec);
}
Can somebody help to point out a direction/solution.
Thanx!