static int64_t GetJsonInt(KonohaContext *kctx, struct JsonBuf *jsonbuf, const char *key, size_t keylen_or_zero, int64_t defval) { JSON json = AsJSON(jsonbuf); if(key == NULL) { if(JSON_TYPE_CHECK(Int32, json)) { return JSONInt_get(json); } else if(JSON_TYPE_CHECK(Int64, json)) { return JSONInt64_get(json); } else { return 0; } } return JSON_getInt(json, key, KeyLen(key, keylen_or_zero)); }
static kbool_t SetJsonArrayAt(KonohaContext *kctx, struct JsonBuf *jsonbuf, size_t index, struct JsonBuf *otherbuf) { if(JSON_TYPE_CHECK(Array, toJSON(jsonbuf->json_i))) { JSONArray_set(toJSON(jsonbuf->json_i), index, toJSON(otherbuf->json_i)); return true; } return false; }
static kbool_t RetrieveJsonArrayAt(KonohaContext *kctx, struct JsonBuf *jsonbuf, size_t index, struct JsonBuf *otherbuf) { if(JSON_TYPE_CHECK(Array, toJSON(jsonbuf->json_i))) { otherbuf->json_i = JSONArray_get(toJSON(jsonbuf->json_i), index).bits; return otherbuf->json_i == 0; } return false; }
static kbool_t AppendJsonArray(KonohaContext *kctx, struct JsonBuf *jsonbuf, struct JsonBuf *otherbuf) { if(JSON_TYPE_CHECK(Array, toJSON(jsonbuf->json_i))) { JSONArray_append((JSONMemoryPool *)(PLATAPI JsonHandler), toJSON(jsonbuf->json_i), toJSON(otherbuf->json_i)); return true; } return false; }
static int64_t GetJsonInt(KonohaContext *kctx, struct JsonBuf *jsonbuf, const char *key, size_t keylen_or_zero, int64_t defval) { if(key == NULL) { if(JSON_TYPE_CHECK(Int32, toJSON(jsonbuf->json_i))) { return JSONInt_get(toJSON(jsonbuf->json_i)); } } return JSON_getInt(toJSON(jsonbuf->json_i), key, KeyLen(key, keylen_or_zero)); }
static kbool_t IsJsonType(struct JsonBuf *jsonbuf, KJSONTYPE type) { switch(type) { case KJSON_OBJECT: return JSON_TYPE_CHECK(Object, toJSON(jsonbuf->json_i)); case KJSON_ARRAY: return JSON_TYPE_CHECK(Array , toJSON(jsonbuf->json_i)); case KJSON_STRING: return JSON_TYPE_CHECK(String, toJSON(jsonbuf->json_i)); case KJSON_INT: return JSON_TYPE_CHECK(Int32 , toJSON(jsonbuf->json_i)); case KJSON_DOUBLE: return JSON_TYPE_CHECK(Double, toJSON(jsonbuf->json_i)); case KJSON_BOOLEAN: return JSON_TYPE_CHECK(Bool , toJSON(jsonbuf->json_i)); case KJSON_NULL: return JSON_TYPE_CHECK(Null , toJSON(jsonbuf->json_i)); case KJSON_INT64: return JSON_TYPE_CHECK(Int64 , toJSON(jsonbuf->json_i)); case KJSON_LONG: return JSON_TYPE_CHECK(Int32 , toJSON(jsonbuf->json_i)); } return false; /* imf */ }
static kbool_t SetJsonKeyValue(KonohaContext *kctx, struct JsonBuf *jsonbuf, const char *key, size_t keylen_or_zero, struct JsonBuf *otherbuf) { if(!JSON_TYPE_CHECK(Object, toJSON(jsonbuf->json_i))) { return false; } size_t keylen = KeyLen(key, keylen_or_zero); JSONObject_set((JSONMemoryPool *)(PLATAPI JsonHandler), toJSON(jsonbuf->json_i), key, keylen, toJSON(otherbuf->json_i)); return true; }
static kbool_t RetrieveJsonArrayAt(KonohaContext *kctx, struct JsonBuf *jsonbuf, size_t index, struct JsonBuf *otherbuf) { JSON json = AsJSON(jsonbuf); if(JSON_TYPE_CHECK(Array, json)) { JSON ret = JSONArray_get(json, index); JSONObject_Retain(ret); otherbuf->json_i = ret.bits; return true; } return false; }
static kbool_t SetJsonKeyValue(KonohaContext *kctx, struct JsonBuf *jsonbuf, const char *key, size_t keylen_or_zero, struct JsonBuf *otherbuf) { JSON json = AsJSON(jsonbuf); size_t keylen; if(!JSON_TYPE_CHECK(Object, json)) { return false; } keylen = KeyLen(key, keylen_or_zero); JSONObject_set((JSONMemoryPool *)(JSONAPI JsonHandler), json, key, keylen, AsJSON(otherbuf)); return true; }