Putting bytes into structures [message #10101] |
Wed, 22 October 1997 00:00 |
jackel[1]
Messages: 11 Registered: May 1997
|
Junior Member |
|
|
Greetings
Here's a question for the collective wisdom:
What's the best way to load a given number of bytes into a structure?
That is, suppose I have some complex structure with floats and strings
and vectors of longints. Then suppose that I have a bytearray that contains
all the information in that structure. How do I put these bytes into the
structure?
One way to do this would be write the bytearray to a temporary file, then read
it into the structure. This is very slow. Alternatively, one could walk
through each tag in the structure, find out how many bytes it needed, grab
that amount from the bytearray, then cast them to the proper type. Faster,
but not exactly elegant.
Ideally, there would be something like READS that would allow unformatted
reading from a bytearray instead of formatted reading from a string.
If anyone has clever ideas (or obvious pointers to documentation that I've
overlooked) please let me know.
Brian Jackel
|
|
|