mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 17:17:09 -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_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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user