fast tiny binary json libaray inspired by bson and message pack,less than 1000 line code you can embed in your application with super speed to transfer data.
type | signature | format |
---|---|---|
number int | 'i' | signature + varint |
number double | 'd' | signature + 8 byte (big endian) |
number float | 'F' | signature + 4 byte (big endian) |
string | 's' | signature + var length + bytes( unicoder utf-16) |
null | '0' | signature |
boolean | 't' or 'f' | signature |
array | '[' | signature + var length + elements |
map | '{' | signature + var size + key, value, key, value |
string length, map size ar store used usigned varint.
here is an example, data in json as follows:
{
"name" : "hello world"
}
in wson
#include "wson/wson_parser.h"
const char* data = readFile("data.wson"); // binary wson data from some where
wson_parser parser(data);
int type = parser.nextType();
if(parser.isMap(type)){
int size = parser.nextMapSize();
for(int i=0; i<size; i++){
std::string key = parser.nextMapKeyUTF8();
uint8_t valueType = parser.nextType();
std::string value = parser.nextStringUTF8(valueType);
printf("map %s == %s \n", key.c_str(), value.c_str());
}
}
const char* data = readFile("data.wson"); // binary wson data from some where
wson_parser parser(data);
int type = parser.nextType();
if(parser.isArray(type)){
int size = parser.nextArraySize();
for(int i=0; i<size; i++){
uint8_t valueType = parser.nextType();
std::string value = parser.nextStringUTF8(valueType);
printf("array %d == %s \n", i, value.c_str());
}
}
Person person = new Person();
byte[] bts = Wson.toWson(person);
byte[] bts = readFile("person.wson");
Map map = (Map)Wson.parse(bts);
if you want more details; please see source and api