mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 01:26:50 -04:00
Future-proof json handler and make it work with over 64k of data
This commit is contained in:
parent
dc878f8da0
commit
07e95ed9e6
@ -161,9 +161,9 @@ static String Json_ConsumeValue(int token, struct JsonContext* ctx) {
|
|||||||
|
|
||||||
static void Json_NullOnNew(struct JsonContext* ctx) { }
|
static void Json_NullOnNew(struct JsonContext* ctx) { }
|
||||||
static void Json_NullOnValue(struct JsonContext* ctx, const String* v) { }
|
static void Json_NullOnValue(struct JsonContext* ctx, const String* v) { }
|
||||||
void Json_Init(struct JsonContext* ctx, String* str) {
|
void Json_Init(struct JsonContext* ctx, STRING_REF char* str, int len) {
|
||||||
ctx->cur = str->buffer;
|
ctx->cur = str;
|
||||||
ctx->left = str->length;
|
ctx->left = len;
|
||||||
ctx->failed = false;
|
ctx->failed = false;
|
||||||
ctx->curKey = String_Empty;
|
ctx->curKey = String_Empty;
|
||||||
|
|
||||||
@ -185,8 +185,7 @@ static void Json_Handle(cc_uint8* data, cc_uint32 len,
|
|||||||
JsonOnValue onVal, JsonOnNew newArr, JsonOnNew newObj) {
|
JsonOnValue onVal, JsonOnNew newArr, JsonOnNew newObj) {
|
||||||
struct JsonContext ctx;
|
struct JsonContext ctx;
|
||||||
/* NOTE: classicube.net uses \u JSON for non ASCII, no need to UTF8 convert characters here */
|
/* 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, (char*)data, len);
|
||||||
Json_Init(&ctx, &str);
|
|
||||||
|
|
||||||
if (onVal) ctx.OnValue = onVal;
|
if (onVal) ctx.OnValue = onVal;
|
||||||
if (newArr) ctx.OnNewArray = newArr;
|
if (newArr) ctx.OnNewArray = newArr;
|
||||||
|
@ -23,7 +23,7 @@ struct JsonContext {
|
|||||||
char _tmpBuffer[STRING_SIZE];
|
char _tmpBuffer[STRING_SIZE];
|
||||||
};
|
};
|
||||||
/* Initialises state of JSON parser. */
|
/* 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. */
|
/* Parses the JSON text, invoking callbacks when value/array/objects are read. */
|
||||||
/* NOTE: DO NOT persist the value argument in OnValue. */
|
/* NOTE: DO NOT persist the value argument in OnValue. */
|
||||||
void Json_Parse(struct JsonContext* ctx);
|
void Json_Parse(struct JsonContext* ctx);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user