-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
57 lines (50 loc) · 1.49 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
52
53
54
55
56
57
#include <iostream>
#include "./httputils.h"
using namespace std;
struct Rect {
int l;
int r;
int d;
int u;
static Rect randomRect() {
auto rect = Rect{rand() % 1000, rand() % 1000, rand() % 1000, rand() % 1000};
if (rect.l > rect.r) swap(rect.l, rect.r);
if (rect.d > rect.u) swap(rect.d, rect.u);
return rect;
}
};
string toRectJson(Rect rect) {
return HttpUtils::mapToJson(
{
{"l", HttpUtils::jsonValue(rect.l)},
{"r", HttpUtils::jsonValue(rect.r)},
{"d", HttpUtils::jsonValue(rect.d)},
{"u", HttpUtils::jsonValue(rect.u)},
}
);
}
string buildDrawPayload(vector<Rect> rects) {
using namespace HttpUtils;
vector<string> jsonRectList;
for (auto r : rects) {
jsonRectList.push_back(toRectJson(r));
}
return HttpUtils::mapToJson(
{
{"rects", HttpUtils::toList(jsonRectList)},
{"type", HttpUtils::jsonValue("draw")},
}
);
}
int main() {
while (true) {
int n = rand() % 100 + 1;
vector<Rect> rects;
for (int i = 0; i < n; i++) {
rects.push_back(Rect::randomRect());
}
string drawingPayload = buildDrawPayload(rects);
cout << "Sending drawing payload with " << rects.size() << " rects" << endl;
HttpUtils::emitJsonToUrl("http://localhost:8888/json/publish", drawingPayload);
}
}