mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: more compression ig
This commit is contained in:
1 parent
6753cedd33
commit
3b1066fade
3 files changed
+24
-15
No files matched your search
@@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
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!).
|
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!).
|
||||||
|
|
||||||
|
1. JSON compressed as BKON, written directly to disk (a direct 50% reduction).
|
||||||
|
2. BKON further compressed with LZ4 (a clean 90% reduction).
|
||||||
|
3. The raw JSON file as fetched from a random data source.
|
||||||
|
4. BKON 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 conversion precision.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Primitives
|
## Primitives
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
|
|||||||
@@ -190,9 +190,13 @@ export class BkonWriteStream extends WriteStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// floats... ignore for now
|
if (object < -0x80000000 || object > 0x7fffffff) {
|
||||||
this.uint8(ValueType.Uint32);
|
this.uint8(ValueType.Float64);
|
||||||
this.uint32(0);
|
this.float64(object);
|
||||||
|
} else {
|
||||||
|
this.uint8(ValueType.Float32);
|
||||||
|
this.float32(object);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (typeof object === 'bigint') {
|
} else if (typeof object === 'bigint') {
|
||||||
if (object < 0) {
|
if (object < 0) {
|
||||||
@@ -275,15 +279,3 @@ export class BkonWriteStream extends WriteStream {
|
|||||||
this.ascii('BKON');
|
this.ascii('BKON');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// const write = new BkonWriteStream();
|
|
||||||
// const data = (await fetch(
|
|
||||||
// 'https://raw.githubusercontent.com/tresabhi/blitzkrieg-assets/dev/definitions/tanks.json',
|
|
||||||
// ).then((response) => response.json())) as Value;
|
|
||||||
// write.bkon(data);
|
|
||||||
// const buffer = write.buffer;
|
|
||||||
// const read = new BkonReadStream(buffer);
|
|
||||||
// read.bkon();
|
|
||||||
|
|
||||||
// writeFile('test.bkon', buffer);
|
|
||||||
// writeFile('test.json', JSON.stringify(data));
|
|
||||||
@@ -143,4 +143,14 @@ export class WriteStream {
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
float32(value: number) {
|
||||||
|
const array = new Float32Array([value]);
|
||||||
|
this.array.push(...new Uint8Array(array.buffer));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
float64(value: number) {
|
||||||
|
const array = new Float64Array([value]);
|
||||||
|
this.array.push(...new Uint8Array(array.buffer));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user