Totte Karlsson <
XXXX@XXXXX.COM >writes:
Quote
hi,
I have a structure :
struct SAMPLE_BLOCK
{
INT8U channelID; // Channel (band) ID for this blocks I/Q data
INT16S sampleI; // In Phase Sample
INT16S sampleQ; // Quadrature Phase Sample
};
I want to write this block to file, except the channelID byte.
So, I just want to write the last four byte in a sample.
How can one do that? I have tried the following, but that don't work
SAMPLE_BLOCK* aSample .....;
fOut->write((char*) &( *(aSample + 1) ), sizeof( *(aSample)) - 1 );
any suggestions?
How about re-order the fields in your structure:
struct Sample_Block
{
INT16S sampleI; // In Phase Sample
INT16S sampleQ; // Quadrature Phase Sample
INT8U channelID; // Channel (band) ID for this blocks I/Q data
};
Then you can write out the beginning of the block by writing out from
the base address:
#include <cstddef>
FOut->write(reinterpret_cast<char*>(aSample),
offsetof(Sample_Block, channelID);
Of course, the offsetof macro requires that your type be POD, but
since your example is, I would expect it represents your real data.
Another way to accomplish this is to introducde a helper structure.
struct Sample_Block
{
struct Streamable
{
INT16S sampleI; // In Phase Sample
INT16S sampleQ; // Quadrature Phase Sample
};
Streamable streamable_data;
INT8U channelID; // Channel (band) ID for this blocks I/Q data
};
Then you can just write out streamable_data in its entirety. Of
course, this changes the way you access its members, so maybe that's
unattractive. You can also use inheritance:
struct Sample_Block_Base
{
INT16S sampleI; // In Phase Sample
INT16S sampleQ; // Quadrature Phase Sample
};
struct Sample_Block : Sample_Block_Base
{
INT8U channelID; // Channel (band) ID for this blocks I/Q data
};
Then you can just write out Sample_Block_Base, but otherwise pass
around the derived type Sample_Block.
Just some ideas.
--
Chris (TeamB);