QuickIO  0.2
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Enumerations | Functions
json.h File Reference

qJSON is a minimal, in-place, zero-allocation JSON packer and unpacker. More...

#include "qev.h"

Go to the source code of this file.

Enumerations

enum  qev_json_status {
  QEV_JSON_OK, QEV_JSON_SPECMEM, QEV_JSON_INSPEC, QEV_JSON_INVAL,
  QEV_JSON_MISMATCH
}
 The maximum number of parts the spec may contain (objects, arrays, values). More...
 

Functions

enum qev_json_status qev_json_unpack (gchar *json, guint *parsed, const gchar *spec,...)
 Variable arguments form of qev_json_vunpack().
 
enum qev_json_status qev_json_vunpack (gchar *json, guint *parsed, const gchar *spec, va_list args)
 Unpack the given JSON object into the given variables. More...
 
enum qev_json_status qev_json_pack (GString *buff, const gchar *spec,...)
 Variable arguments form of qev_json_vpack().
 
enum qev_json_status qev_json_vpack (GString *buff, const gchar *spec, va_list args)
 Packs the given values into a JSON object. More...
 

Detailed Description

qJSON is a minimal, in-place, zero-allocation JSON packer and unpacker.

The following specs are supported:

Todo:
write some examples for json usage
Author
Andrew Stone andre.nosp@m.w@cl.nosp@m.ovar..nosp@m.com

Enumeration Type Documentation

The maximum number of parts the spec may contain (objects, arrays, values).

Possible return codes of any operation

Enumerator
QEV_JSON_OK 

Everything went as expected.

All values are good to use.

QEV_JSON_SPECMEM 

If the spec has too many parts.

In reality, if you ever encounter this, then you should probably use a different parser that has more complete memory management. If you're sure you want to use this, increase JSON_MAX_PARTS.

QEV_JSON_INSPEC 

The spec was invalid.

QEV_JSON_INVAL 

The JSON was improperly formatted.

QEV_JSON_MISMATCH 

The JSON was valid but didn't match the spec or didn't completely fill all requested values.

Function Documentation

enum qev_json_status qev_json_vpack ( GString *  buff,
const gchar *  spec,
va_list  args 
)

Packs the given values into a JSON object.

Parameters
buffWhere the packed JSON should be placed. The JSON is only appended to the string, so if you only want JSON in the string, be sure the string is empty before passing it in.
specThe json-ish spec used to pack into JSON.
argsThe values to pack.
Returns
The status of packing.
enum qev_json_status qev_json_vunpack ( gchar *  json,
guint *  parsed,
const gchar *  spec,
va_list  args 
)

Unpack the given JSON object into the given variables.

Parameters
jsonThe JSON to unpack. This will be modified in place and unpacked into the values, so once this becomes invalid, all gchar* values passed in also become invalid.
[out]parsedThe number of characters parsed. When json_ok, this is the number of JSON characters parsed (it's possible that this is less than the length of the JSON string when all values are found before parsing finishes). When json_inspec, this is the number of spec characters parsed. Practically speaking, on error, the character at this offset is the beginning of the parse error. [allow-null]
specThe json-ish spec used to unpack the JSON into the given variables.
argsWhere the found values should be placed.
Returns
Unpacking status.