diff options
| author | Jesper Jensen <jesper@slashwin.dk> | 2021-08-28 22:27:24 +0200 |
|---|---|---|
| committer | Jesper Jensen <jesper@slashwin.dk> | 2021-08-28 22:27:24 +0200 |
| commit | e00efb4381c5123699e4ef9807b67eba54ea06a0 (patch) | |
| tree | df2d7567a20e2313d576fb00aab61be8ee3383fa /src/benc.h | |
| parent | de3bec63c63b0c30a5a4e1d9b4a5478984b888e9 (diff) | |
Initial fanout implemented
Diffstat (limited to 'src/benc.h')
| -rw-r--r-- | src/benc.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/benc.h b/src/benc.h new file mode 100644 index 0000000..a5734ea --- /dev/null +++ b/src/benc.h @@ -0,0 +1,31 @@ +#pragma once + +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <unistd.h> + +enum benc_nodetype { + BNT_INT, + BNT_STRING, + BNT_LIST, + BNT_DICT, + BNT_END, +}; + +struct benc_node { + enum benc_nodetype type; + const char* loc; + union { + size_t size; + uint32_t depth; + }; +}; + +bool readint(const char** loc, int64_t* val); + +void benc_print(const struct benc_node* stream, size_t stream_len, int* depth); +int64_t benc_decode(const char** cursor, const char* end, int* depth, struct benc_node* stream, size_t stream_len); + +void skip_sibling(const struct benc_node** cursor, const struct benc_node* end); +ssize_t skip_to_key(const struct benc_node** cursor, const struct benc_node* end, const enum benc_nodetype* keyTypes, const char** keyValues, const size_t* keyLengths, const size_t keys); |
