-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPacket.cpp
31 lines (26 loc) · 905 Bytes
/
Packet.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "Packet.hpp"
Packet::Packet() {}
Packet::Packet(Packet_Header& header,
Packet_Payloads& payloads) :
header(header), payloads(payloads) {
//std::cout << "Copy constructor called\n";
}
// takes a packet and a container of packets,
// and appends all the payloads from the packets in the container
// to that of the packet
// should have a way to set limit on number here!
Packet Packet::piggyback(const Packet& p, const Packets& packets) {
Packet ret = p;
Packet_Payloads& payloads = ret.payloads;
for (const auto& packet: packets) {
concat(payloads, packet.payloads);
}
// convert 6,3,4,5 -> 3,4,5,6
if (payloads.size() > 1) {
const Packet_Payload payload = payloads.front();
payloads.pop_front();
payloads.emplace_back(payload);
}
assert(ret.header.sender_id < 8 && "IN PIGGYBACK\n");
return ret;
}