Future-proof json handler and make it work with over 64k of data

This commit is contained in:
UnknownShadow200 2020-05-02 13:55:51 +10:00
parent dc878f8da0
commit 07e95ed9e6
2 changed files with 5 additions and 6 deletions

View File

@ -161,9 +161,9 @@ static String Json_ConsumeValue(int token, struct JsonContext* ctx) {
static void Json_NullOnNew(struct JsonContext* ctx) { }
static void Json_NullOnValue(struct JsonContext* ctx, const String* v) { }
void Json_Init(struct JsonContext* ctx, String* str) {
ctx->cur = str->buffer;
ctx->left = str->length;
void Json_Init(struct JsonContext* ctx, STRING_REF char* str, int len) {
ctx->cur = str;
ctx->left = len;
ctx->failed = false;
ctx->curKey = String_Empty;
@ -185,8 +185,7 @@ static void Json_Handle(cc_uint8* data, cc_uint32 len,
JsonOnValue onVal, JsonOnNew newArr, JsonOnNew newObj) {
struct JsonContext ctx;
/* NOTE: classicube.net uses \u JSON for non ASCII, no need to UTF8 convert characters here */
String str = String_Init((char*)data, len, len);
Json_Init(&ctx, &str);
Json_Init(&ctx, (char*)data, len);
if (onVal) ctx.OnValue = onVal;
if (newArr) ctx.OnNewArray = newArr;

View File

@ -23,7 +23,7 @@ struct JsonContext {
char _tmpBuffer[STRING_SIZE];
};
/* Initialises state of JSON parser. */
void Json_Init(struct JsonContext* ctx, String* str);
void Json_Init(struct JsonContext* ctx, STRING_REF char* str, int len);
/* Parses the JSON text, invoking callbacks when value/array/objects are read. */
/* NOTE: DO NOT persist the value argument in OnValue. */
void Json_Parse(struct JsonContext* ctx);