From 07e95ed9e6a7570a5f9ff5ccb95172f4901d52e2 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 2 May 2020 13:55:51 +1000 Subject: [PATCH] Future-proof json handler and make it work with over 64k of data --- src/LWeb.c | 9 ++++----- src/LWeb.h | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/LWeb.c b/src/LWeb.c index b82a3892d..30810783d 100644 --- a/src/LWeb.c +++ b/src/LWeb.c @@ -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; diff --git a/src/LWeb.h b/src/LWeb.h index 7a7ca6cd6..ce816b2aa 100644 --- a/src/LWeb.h +++ b/src/LWeb.h @@ -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);