
On Thu, 11 Oct 2007 08:40:21 +0200, Roland Schwarz <roland.schwarz@chello.at> wrote:
I am searching for a library / component / pattern that will help me with the following problem:
I have a memory structure in raw memory (received from a measurement instrument), that is unaligned in its data members.
Now I want to have an access interface to this data that comes as close as possible to access of a struct. E.g.
struct foo { char a; int b; }
Altough my raw data "char* pdata" has an 8bit followed by a 32bit I want to be able to do something like:
foo data(pdata);
and then
char ch = data.a; int n = data.b;
Does anyone know about such a library? (This should work compiler/platform independent of course.)
class foo { private: unsigned char internals[5]; public: char a() {return internals[0];} int b() { // select code block depending on your endianness unsigned int n=(a[0]<<24)|(a[1]<<16]|(a[2]<<8)|a[3]; unsigned int n=(a[3]<<24)|(a[2]<<16]|(a[1]<<8)|a[0]; return static_cast<int>(n); } };