Clean up backend detection flow.
This commit is contained in:
27
common.h
27
common.h
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user