I have a structure:
//Custom packet structure. struct UserPacket { __int64 pingTime; } CustomPacket;
I already figured out how to convert it to char *. Now I want to convert char * back to a structure. Any suggestions?
If it is C ++:
char* theCharPtr; // has your converted data UserPacket* fromChar = reinterpret_cast<UserPacket*>(theCharPtr);
Typecast it. Here are a few examples (two using casting types).
CustomPacket customPacket; char * p = (char *) &customPacket; CustomPacket * pPacket = (CustomPacket *) p; CustomPacket * pAlternate = &customPacket;
Hope this helps.
Source: https://habr.com/ru/post/1306604/More articles:Iterative collection in two threads - javaCan an algorithmic process produce true random numbers? - randomDoes python-memcached support serial hashing and binary protocol? - pythonHow to ignore / prevent javadoc folder check during Eclipse build? - eclipseOleDB Jet - problems with floating point when reading Excel data - floating-pointTemporal complexity of the sorting algorithm - cIn Django, I want to insert a database record by sending me an email? - pythonIs there an equivalent Java ClassFileTransformer in .NET? (a way to replace a class) - reflectionWhat is natural deduction used outside of academia? - logicGame architecture: modeling of various steps / types of user interface - design-patternsAll Articles