-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapperInputT.cpp
103 lines (76 loc) · 2.56 KB
/
MapperInputT.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
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
//
// Created by Matilde Pulidori on 18/05/2020.
//
#include <fstream>
#include <sstream>
#include <regex>
#include "MapperInputT.h"
MapperInputT::MapperInputT(std::string line): line(std::move(line)) {
this->parser(this->line);
std::vector<char> ser = this->serialize();
this->deserialize(ser);
}
MapperInputT::~MapperInputT() = default;
void MapperInputT::parser(std::string line){
std::stringstream stringstream(line);
std::string word;
std::getline(stringstream, word, ' '); // ip_
std::smatch w;
std::regex_search(word, w, std::regex("^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}"));
this->ip=w[0];
/*std::getline(stringstream, w, ' '); // -_
std::getline(stringstream, w, ' '); // -_
std::getline(stringstream, w, ' '); // [data:ora_
std::stringstream dataora(w);
std::string timestamp;
std::getline(dataora, w, ':'); // [data:
std::getline(dataora, timestamp, ' '); // ora
this->time = timestamp;
std::getline(stringstream, w, ' '); // fuso]_
std::getline(stringstream, w, ' '); // "METHOD_
size_t toRemove = w.find('"');
w.erase(toRemove,1 );
this->method = w;
std::getline(stringstream, w, '"'); // HTTP/1.1"
std::getline(stringstream, w, ' '); // _
std::getline(stringstream, w, ' '); // <CODE>_
this->code = w;*/
}
std::string MapperInputT::getLine() const {
return line;
}
std::string MapperInputT::getIp() const {
return ip;
}
std::string MapperInputT::getTime() const {
return time;
}
std::string MapperInputT::getMethod() const {
return method;
}
std::string MapperInputT::getCode() const {
return code;
}
std::vector<char> MapperInputT::serialize() {
ushort sizeString = sizeof(std::string);
ushort sizeTot = sizeString + sizeof(ushort);
std::vector<char> buff(sizeTot);
std::copy((char*)&sizeString, (char*)&sizeString + sizeof(ushort), buff.begin()); // { <lunghezza attributo ip>
std::copy((char*)&ip, (char*)&ip + sizeString, buff.begin()+ sizeof(ushort));// <valore attributo ip>}
return buff;
}
void MapperInputT::deserialize(std::vector<char> buff) {
ushort sizeTot = buff.size();
ushort position = 0;
ushort toAdd = sizeof(ushort);
ushort toAddNext = 0;
while (position <= sizeTot) {
if(toAdd == sizeof(ushort)) {
std::copy(buff.begin() + position, buff.begin() + position + toAdd, (char *) &toAddNext);
} else {
std::copy(buff.begin() + position, buff.begin() + position + toAdd, (char *) &this->ip);
}
position +=toAdd;
toAdd += toAddNext;
}
}