Raw send support.
This commit is contained in:
34
raw.c
34
raw.c
@@ -47,6 +47,24 @@ static bool raw_parse_mode_s_long(struct buf *buf, struct packet *packet) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void raw_serialize_mode_s_short(struct packet *packet, struct buf *buf) {
|
||||||
|
struct raw_mode_s_short_overlay *overlay = (struct raw_mode_s_short_overlay *) buf_at(buf, 0);
|
||||||
|
overlay->asterisk = '*';
|
||||||
|
overlay->semicolon = ';';
|
||||||
|
overlay->lf = '\n';
|
||||||
|
hex_from_bin(overlay->payload, packet->payload, sizeof(overlay->payload) / 2);
|
||||||
|
buf->length = sizeof(*overlay);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void raw_serialize_mode_s_long(struct packet *packet, struct buf *buf) {
|
||||||
|
struct raw_mode_s_long_overlay *overlay = (struct raw_mode_s_long_overlay *) buf_at(buf, 0);
|
||||||
|
overlay->asterisk = '*';
|
||||||
|
overlay->semicolon = ';';
|
||||||
|
overlay->lf = '\n';
|
||||||
|
hex_from_bin(overlay->payload, packet->payload, sizeof(overlay->payload) / 2);
|
||||||
|
buf->length = sizeof(*overlay);
|
||||||
|
}
|
||||||
|
|
||||||
void raw_init() {
|
void raw_init() {
|
||||||
assert(sizeof(struct raw_mode_s_short_overlay) < BUF_LEN_MAX);
|
assert(sizeof(struct raw_mode_s_short_overlay) < BUF_LEN_MAX);
|
||||||
assert(sizeof(struct raw_mode_s_long_overlay) < BUF_LEN_MAX);
|
assert(sizeof(struct raw_mode_s_long_overlay) < BUF_LEN_MAX);
|
||||||
@@ -57,3 +75,19 @@ bool raw_parse(struct buf *buf, struct packet *packet, void *state_in) {
|
|||||||
raw_parse_mode_s_short(buf, packet) ||
|
raw_parse_mode_s_short(buf, packet) ||
|
||||||
raw_parse_mode_s_long(buf, packet));
|
raw_parse_mode_s_long(buf, packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void raw_serialize(struct packet *packet, struct buf *buf) {
|
||||||
|
if (!packet) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (packet->type) {
|
||||||
|
case MODE_S_SHORT:
|
||||||
|
raw_serialize_mode_s_short(packet, buf);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MODE_S_LONG:
|
||||||
|
raw_serialize_mode_s_long(packet, buf);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
1
raw.h
1
raw.h
@@ -7,3 +7,4 @@ struct packet;
|
|||||||
|
|
||||||
void raw_init();
|
void raw_init();
|
||||||
bool raw_parse(struct buf *, struct packet *, void *);
|
bool raw_parse(struct buf *, struct packet *, void *);
|
||||||
|
void raw_serialize(struct packet *, struct buf *);
|
||||||
|
|||||||
5
send.c
5
send.c
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "beast.h"
|
#include "beast.h"
|
||||||
#include "json.h"
|
#include "json.h"
|
||||||
|
#include "raw.h"
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
|
|
||||||
struct send {
|
struct send {
|
||||||
@@ -37,6 +38,10 @@ struct serializer {
|
|||||||
.name = "json",
|
.name = "json",
|
||||||
.serialize = json_serialize,
|
.serialize = json_serialize,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.name = "raw",
|
||||||
|
.serialize = raw_serialize,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.name = "stats",
|
.name = "stats",
|
||||||
.serialize = stats_serialize,
|
.serialize = stats_serialize,
|
||||||
|
|||||||
Reference in New Issue
Block a user