-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPacket.cpp
More file actions
101 lines (83 loc) · 2.15 KB
/
Packet.cpp
File metadata and controls
101 lines (83 loc) · 2.15 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <string>
#include <iostream>
#include "Packet.h"
// TODO implementar tema de flags y offsets
Packet::Packet(string id, string src, string dst, unsigned char flag,
short offset, short len) {
this->id = id;
this->src = src;
this->dst = dst;
this->data = "";
this->flag = flag;
this->offset = offset;
this->len = len;
complete = (offset == 0 && flag ==0);
}
Packet::~Packet() {
//por ahora nada que hacer
}
const string &Packet::getData() const {
return data;
}
short Packet::getLength() const {
return len;
}
const string Packet::getId() const {
return id;
}
const string Packet::getSrc() const {
return src;
}
const string Packet::getDst() const {
return dst;
}
const bool Packet::is_complete() const {
return complete;
}
void Packet::setData(const string &data) {
Packet::data = data;
}
bool Packet::operator==(const Packet& other) const{
bool match_src = this->src == other.src;
bool match_dst = this->dst == other.dst;
bool match_id = this->id == other.id;
return match_dst && match_src && match_id;
}
bool Packet::operator>(const Packet& other) const{
//el mayor es el ultimo
return offset > other.offset;
}
bool Packet::operator<(const Packet& other) const{
//el mayor es el ultimo
return offset < other.offset;
}
bool Packet::is_first() const{
return offset == 0;
}
bool Packet::is_last() const{
return flag == 0;
}
bool Packet::is_next(const Packet& other){
// std::cout << "off + len: " << offset + len <<std::endl;
// std::cout << "otro off: " << other.offset << std::endl;
return (offset + len) == other.offset;
}
int Packet::mergePacket(const Packet& nextPacket ){
if (!is_next(nextPacket)){ return -1; }
string first_data = this->data;
string next_data = nextPacket.data;
string complete_data = first_data + " " + next_data;
this->data = complete_data;
this->len += nextPacket.len;
this->flag = nextPacket.flag;
if (is_first() && nextPacket.is_last()){
complete = true;
}
return 0;
}
short Packet::getOffset() const {
return offset;
}
unsigned char Packet::getFlag() const {
return flag;
}