Files
blitzkit/docs/guide/cdon.md
T

173 lines
2.9 KiB
Markdown
Raw Normal View History

2024-02-07 10:02:00 -06:00
# Cedilla Object Notation
2024-02-04 11:06:26 -06:00
2024-02-04 18:48:39 -06:00
A compact binary representation similar to JSON objects. This documentation uses some funky (yet concise) syntax I developed (don't worry, my C++ isn't that bad!).
2024-02-04 11:06:26 -06:00
2024-02-07 10:02:00 -06:00
1. JSON compressed as CDON, written directly to disk (a direct 50% reduction).
2. CDON further compressed with LZ4 (a clean 90% reduction).
2024-02-04 21:40:40 -06:00
3. The raw JSON file as fetched from a random data source.
2024-02-07 10:02:00 -06:00
4. CDON decompressed once again to JSON. Note that this file is a little larger than the original JSON file as it contains a lot more decimal places due to float precision (this shouldn't affect the size in memory).
2024-02-04 21:40:40 -06:00
2024-02-04 21:47:11 -06:00
![an image of file sizes](https://i.imgur.com/AHJiFpq.png)
2024-02-04 21:40:40 -06:00
2024-02-04 11:06:26 -06:00
## Primitives
```cpp
struct String {
uint32 length;
2024-02-05 18:06:18 -06:00
utf8[length] value;
2024-02-04 11:06:26 -06:00
}
```
## Reading
- Everything is little endian
2024-02-07 10:02:00 -06:00
- Magic is always `"CDON"`
2024-02-05 13:33:23 -06:00
- The index of fast strings must be read as mentioned by the fast string format
2024-02-04 11:06:26 -06:00
```cpp
struct BlitzkriegObjectNotation {
ascii[4] magic;
Header header;
Body body;
}
```
### Header
- Version is always `1`
```cpp
struct Header {
uint16 version;
2024-02-05 13:33:23 -06:00
FastStringFormat fastStringFormat;
2024-02-04 11:06:26 -06:00
StringTable stringTable;
}
2024-02-05 13:33:23 -06:00
// read as uint8
enum FastStringFormat {
Format8,
Format16,
Format32,
}
2024-02-04 11:06:26 -06:00
struct StringTable {
2024-02-05 13:33:23 -06:00
(uint8 | uint16 | uint32) count;
2024-02-04 11:06:26 -06:00
String[count] strings;
}
```
### Body
```cpp
struct Body {
2024-02-04 21:10:44 -06:00
Value object;
2024-02-04 11:06:26 -06:00
}
2024-02-04 21:10:44 -06:00
// read as uint8
2024-02-04 11:06:26 -06:00
enum ValueType {
Null,
Boolean,
Uint8,
Uint16,
Uint32,
Uint64,
Int8,
Int16,
Int32,
Int64,
Float32,
Float64,
String,
FastString,
Array,
Object,
}
2024-02-04 18:48:39 -06:00
struct Value = `Value${ValueType}`
2024-02-04 11:06:26 -06:00
struct ValueNull {
ValueType.Null type;
}
struct ValueBoolean {
ValueType.Boolean type;
uint8 value;
}
struct ValueUint8 {
ValueType.Uint8 type;
uint8 value;
}
struct ValueUint16 {
ValueType.Uint16 type;
uint16 value;
}
struct ValueUint32 {
ValueType.Uint32 type;
uint32 value;
}
struct ValueUint64 {
ValueType.Uint64 type;
uint64 value;
}
struct ValueInt8 {
ValueType.Int8 type;
int8 value;
}
struct ValueInt16 {
ValueType.Int16 type;
int16 value;
}
struct ValueInt32 {
ValueType.Int32 type;
int32 value;
}
struct ValueInt64 {
ValueType.Int64 type;
int64 value;
}
struct ValueFloat32 {
ValueType.Float32 type;
float32 value;
}
struct ValueFloat64 {
ValueType.Float64 type;
float64 value;
}
struct ValueString {
ValueType.String type;
String value;
}
struct ValueFastString {
ValueType.FastString type;
2024-02-05 13:33:23 -06:00
(uint8 | uint16 | uint32) index;
2024-02-04 11:06:26 -06:00
}
struct ValueArray {
ValueType.Array type;
uint32 count;
Value[count] values;
}
struct ValueObject {
ValueType.Object type;
uint32 count;
(ValueString | ValueFastString)[count] keys;
Value[count] values;
}
```
## Writing
2024-02-04 21:41:58 -06:00
It's pretty obvious how to write. Remember that a `FastString` should only be applied to the string table if the string shows up more than once in the body. Otherwise, there's no point and `String` should be used.