forked from whiteblock/hobbits
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.cpp
52 lines (42 loc) · 1.05 KB
/
main.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
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <istream>
#include "request.h"
using namespace std;
string parse_input(size_t size){
const size_t buffer_size = 100;
size_t len = 0;
string out;
char buffer[buffer_size];
while(len < size){
size_t max_to_read = std::min(buffer_size - 1,size - len);
cin.read(buffer,max_to_read);
out.append(buffer,max_to_read);
len += max_to_read;
}
return out;
}
int main(int argc,char** argv)
{
if(argc == 1){
hobbit::ewp_request req(string("EWP 0.2 PING 0 5\n12345"));
cout<<req.marshal()<<endl<<endl;
return EXIT_SUCCESS;
}
if(argc == 2) {
cout<<"Missing a size argument"<<endl;
return EXIT_FAILURE;
}
size_t size = atol(argv[2]);
string type(argv[1]);
string input = parse_input(size);
if(type == "request"){
hobbit::ewp_request req(input);
cout<<req.marshal();
}else{
cout<<"Unknown option"<<endl;
}
return EXIT_SUCCESS;
}