src/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
31 / 31
100.0%
Branches:
13 / 24
54.2%
Functions:
5 / 5
100.0%

ProtoFrame.cpp
Line Branch Exec Source
1 #include "ProtoFrame.h"
2
3 47 void beginFrame(JsonFormatter &json, proto_type_t type, uint32_t id) {
4 47 json.beginObject();
5 47 json.addElem("v", (uint8_t)PROTO_VERSION);
6 47 json.addElem("t", static_cast<uint8_t>(type));
7
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 45 times.
47 if(id) json.addElem("id", id);
8 47 json.beginObject("d");
9 47 }
10 47 void endFrame(JsonFormatter &json) {
11 47 json.endObject();
12 47 json.endObject();
13 47 }
14 1 void writeOkReply(JsonFormatter &json, uint32_t id) {
15 1 beginFrame(json, proto_type_t::reply, id);
16
1/2
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
1 ProtoWriter(json).add(proto_field_t::ok, true);
17 1 endFrame(json);
18 1 }
19 1 void writeErrorReply(JsonFormatter &json, uint32_t id, proto_error_t code, const char *desc) {
20
1/2
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
1 beginFrame(json, proto_type_t::reply, id);
21 1 ProtoWriter w(json);
22
1/2
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
1 w.add(proto_field_t::ok, false);
23
1/2
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
1 w.add(proto_field_t::code, static_cast<uint8_t>(code));
24
1/2
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
1 w.add(proto_field_t::desc, desc);
25
1/2
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
1 endFrame(json);
26 1 }
27 1 void writeHello(JsonFormatter &json, const char *fw) {
28
1/2
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
1 beginFrame(json, proto_type_t::hello);
29 1 ProtoWriter w(json);
30
1/2
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
1 w.add(proto_field_t::fw, fw);
31
2/4
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
1 w.add(proto_field_t::schemaHash, protoSchemaHash());
32
1/2
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
1 endFrame(json);
33 1 }
34