[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ns] variable length packet header



Hi,

I've created a new header to acknowledge received messages at one node. This 
node sends acknowledge packets every x ms. The problem is that, in this period 
of time, this node can receive 1 but also ... 1000 messages to acknowledge. 
Therefore I would like not to have a fixed array with the length 1000 that would 
be often unused but a dynamic array whose length would grow with the number of 
messages to acknowldege. 

So now, I have something like that :

in <rack.h> :

struct hdr_rack {
	
	int sess_id_[1000]; 
		
	static int offset_;
	inline static int& offset() { return offset_; }
	inline static hdr_rack* access(Packet* p) {
		return (hdr_rack*) p->access(offset_);
	}

	int& sess_id(int i) {return sess_id_[i];}
};

and in <rack.cc> :

int hdr_rack::offset_;

static class RackHeaderClass : public PacketHeaderClass {
public:
	RackHeaderClass() : PacketHeaderClass("PacketHeader/Rack",
					      sizeof(hdr_rack)) {
		bind_offset(&hdr_rack::offset_);
	}
	void export_offsets() {
		field_offset("sess_id_", OFFSET(hdr_rack, sess_id_));
	}
} class_rackhdr;

What do I need to change to have this sess_id_ array dynamic ??

Thanks a lot for your answers

      Jan.