tags:

views:

78

answers:

2

hi i'm working on a personal project for a transport parser.

i want to be able to represent a recived packet in binary number and afterwards be able to set specific bits. I've got a pretty good idea how to do the second part but i'm really stuck at the beginning ive got an advice to use unsigned char for that but can i really represent a full packet in that variable.

thanks

+1  A: 

an unsigned char array is probably what you need: you can store whatever you want in this structure and access it in whatever means pleases you.

You could have this container in a bigger container too: the bigger container would have pointers to the each layer's beginning & end etc.

jldupont
in C++ I'd recommend using std::vector<unsigned char>. For OP, just look at 'arrays in C' in google..
Yossarian
A: 

I'd probably have a simple class (simple to begin with anyway):

class Packet
{
public:
 Packet(unsigned int length);
 Packet(void *data);
 bool getBit(unsigned int bit);
 void setBit(unsigned int bit,bool set);
private:
 std::vector<unsigned char> bytes;
};

That's just to start, no doubt it would get more complex depending what you use it for. You might consider overloading the array operator but that's probably outside "beginner level" and maybe best ignored right now.

John