Convert everything to c api

This commit is contained in:
2025-05-23 11:59:50 -04:00
parent f7ad84a79a
commit 1217ded8a7
8 changed files with 130 additions and 89 deletions

View File

@@ -1,25 +1,33 @@
#include "parser3.h"
#include "weaseljson.h"
using namespace parser3;
extern "C" {
/** Create a parser. Increasing stack size increases memory usage but also
* increases the depth of nested json accepted. `callbacks` and `data` must
* outlive the returned parser. */
__attribute__((visibility("default"))) WeaselJsonParser *
WeaselJsonParser_create(int stackSize, const WeaselJsonCallbacks *callbacks,
void *data) {}
/** Restore the parser to its newly-created state */
__attribute__((visibility("default"))) void
WeaselJsonParser_reset(WeaselJsonParser *parser) {}
/** Destroy the parser */
__attribute__((visibility("default"))) void
WeaselJsonParser_destroy(WeaselJsonParser *parser) {}
/** Incrementally parse `len` more bytes starting at `buf`. `buf` may be
* modified. Call with `len` 0 to indicate end of data */
__attribute__((visibility("default"))) WeaselJsonStatus
WeaselJsonParser_parse(WeaselJsonParser *parser, char *buf, int len) {}
void *data) {
auto *buf = malloc(sizeof(Parser3) + stackSize);
if (buf == nullptr) {
return nullptr;
}
return (WeaselJsonParser *)new (buf) Parser3{callbacks, data, stackSize};
}
__attribute__((visibility("default"))) void
WeaselJsonParser_reset(WeaselJsonParser *parser) {
((Parser3 *)parser)->reset();
}
__attribute__((visibility("default"))) void
WeaselJsonParser_destroy(WeaselJsonParser *parser) {
((Parser3 *)parser)->~Parser3();
free(parser);
}
__attribute__((visibility("default"))) WeaselJsonStatus
WeaselJsonParser_parse(WeaselJsonParser *parser, char *buf, int len) {
return ((Parser3 *)parser)->parse(buf, len);
}
}