More proto parsing.

This commit is contained in:
Ian Gulliver
2016-02-23 16:43:36 -08:00
parent a33808cb33
commit 4f48153d4f
2 changed files with 23 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "buf.h"
@@ -48,7 +49,22 @@ static void proto_serialize_mode_s_long(struct packet *packet, struct buf *buf)
}
bool proto_parse(struct buf *buf, struct packet *packet, void *state_in) {
Adsb *wrapper = adsb__unpack(NULL, buf->length, (uint8_t *) buf_at(buf, 0));
if (!wrapper) {
return false;
}
if (!wrapper->header &&
!wrapper->mode_s_short &&
!wrapper->mode_s_long) {
// "oneof" is actually "zero or oneof"
adsb__free_unpacked(wrapper, NULL);
return false;
}
buf_consume(buf, adsb__get_packed_size(wrapper));
adsb__free_unpacked(wrapper, NULL);
packet->type = PACKET_TYPE_NONE; // XXX
return true;
}
void proto_serialize(struct packet *packet, struct buf *buf) {

View File

@@ -10,6 +10,7 @@
#include "json.h"
#include "packet.h"
#include "peer.h"
#include "proto.h"
#include "raw.h"
#include "send.h"
#include "uuid.h"
@@ -47,6 +48,10 @@ struct parser {
.name = "json",
.parse = json_parse,
},
{
.name = "proto",
.parse = proto_parse,
},
{
.name = "raw",
.parse = raw_parse,
@@ -99,7 +104,7 @@ static void receive_read(struct peer *peer) {
struct packet packet = {
.source_id = receive->id,
};
while (receive->parser_wrapper(receive, &packet)) {
while (receive->buf.length && receive->parser_wrapper(receive, &packet)) {
if (packet.type == PACKET_TYPE_NONE) {
continue;
}