Clean up backend detection flow.

This commit is contained in:
Ian Gulliver
2016-02-15 19:07:56 +00:00
parent 7986d40569
commit f47e1e766b
4 changed files with 42 additions and 42 deletions

View File

@@ -1,12 +1,8 @@
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
//////// misc
#define PARSER_STATE_LEN 256
//////// buf
#define BUF_LEN_MAX 256
@@ -15,6 +11,10 @@ struct buf {
size_t start;
size_t length;
};
#define BUF_INIT { \
.start = 0, \
.length = 0, \
}
#define buf_chr(buff, at) ((buff)->buf[(buff)->start + (at)])
#define buf_at(buff, at) (&buf_chr(buff, at))
@@ -40,6 +40,23 @@ struct packet {
};
//////// backend
#define PARSER_STATE_LEN 256
struct backend;
typedef bool (*parser)(struct backend *, struct packet *);
struct backend {
struct buf buf;
char parser_state[PARSER_STATE_LEN];
parser parser;
};
#define BACKEND_INIT { \
.buf = BUF_INIT, \
.parser_state = { 0 }, \
.parser = backend_autodetect_parse, \
}
//////// hex
void hex_init();
void hex_to_bin(char *, char *, size_t);