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 | 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 | 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 | beginFrame(json, proto_type_t::reply, id); | |
| 21 | 1 | ProtoWriter w(json); | |
| 22 | 1 | w.add(proto_field_t::ok, false); | |
| 23 | 1 | w.add(proto_field_t::code, static_cast<uint8_t>(code)); | |
| 24 | 1 | w.add(proto_field_t::desc, desc); | |
| 25 | 1 | endFrame(json); | |
| 26 | 1 | } | |
| 27 | 1 | void writeHello(JsonFormatter &json, const char *fw) { | |
| 28 | 1 | beginFrame(json, proto_type_t::hello); | |
| 29 | 1 | ProtoWriter w(json); | |
| 30 | 1 | w.add(proto_field_t::fw, fw); | |
| 31 | 1 | w.add(proto_field_t::schemaHash, protoSchemaHash()); | |
| 32 | 1 | endFrame(json); | |
| 33 | 1 | } | |
| 34 |