-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageParser.cpp
More file actions
42 lines (40 loc) · 1.01 KB
/
MessageParser.cpp
File metadata and controls
42 lines (40 loc) · 1.01 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
#include <iostream>
#include<vector>
#include<iostream>
#include <sstream>
#include<algorithm>
#include "MessageParser.h"
#include "Util.h"
#include "Logger.h"
void MessageParser::parse(const std::string &input) {
std::istringstream ss(input);
std::string token;
try {
std::getline(ss, token, ',');
int c = str2i(token);
if( c==0 ) {
int id;
int side;
int size;
double price;
std::getline(ss, token, ',');
id = str2i(token);
std::getline(ss, token, ',');
side = str2i(token);
std::getline(ss, token, ',');
size = str2i(token);
std::getline(ss, token, ',');
price = str2d(token);
if(validate_input(id, side, size, price)) book.match_order(id, side, price, size);
} else if( c==1 ) {
int id;
std::getline(ss, token, ',');
id = str2i(token);
if(validate_input(id, 1, -1, -1, true)) book.cancel_order(id);
} else {
LOG(ERROR) << "Bad Request: Invalid order type.";
}
} catch(...) {
LOG(ERROR) << "Bad Input: Unexpected or out of range datatype detected.";
}
}