feat: rename to cdon

This commit is contained in:
TrèsAbhi committed 2024-02-07 10:02:00 -06:00
1 parent 901f1bfe42
commit 9cfa2357b0
12 files changed
+49 -49

No files matched your search

+1 -1
View File
@@ -13,10 +13,10 @@
"bepaint",
"BINORMAL",
"Binormals",
"BKON",
"bkwd",
"blitzstars",
"Camo",
"CDON",
"classname",
"cleandist",
"cockroackdb",
+5 -5
View File
@@ -1,11 +1,11 @@
# Blitzkrieg Object Notation
# Cedilla Object Notation
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).
1. JSON compressed as CDON, written directly to disk (a direct 50% reduction).
2. CDON 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 precision (this shouldn't affect the size in memory).
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).
![an image of file sizes](https://i.imgur.com/AHJiFpq.png)
@@ -21,7 +21,7 @@ struct String {
## Reading
- Everything is little endian
- Magic is always `"BKON"`
- Magic is always `"CDON"`
- The index of fast strings must be read as mentioned by the fast string format
```cpp
+5 -5
View File
@@ -915,27 +915,27 @@ export async function definitions(production: boolean) {
{
content: superCompress(tankDefinitions),
encoding: 'base64',
path: 'definitions/tanks.bkon.lz4',
path: 'definitions/tanks.cdon.lz4',
},
{
content: superCompress(modelDefinitions),
encoding: 'base64',
path: 'definitions/models.bkon.lz4',
path: 'definitions/models.cdon.lz4',
},
{
content: superCompress(equipmentDefinitions),
encoding: 'base64',
path: 'definitions/equipment.bkon.lz4',
path: 'definitions/equipment.cdon.lz4',
},
{
content: superCompress(consumableDefinitions),
encoding: 'base64',
path: 'definitions/consumables.bkon.lz4',
path: 'definitions/consumables.cdon.lz4',
},
{
content: superCompress(provisionDefinitions),
encoding: 'base64',
path: 'definitions/provisions.bkon.lz4',
path: 'definitions/provisions.cdon.lz4',
},
],
production,
+3 -3
View File
@@ -1,5 +1,5 @@
import { asset } from './asset';
import { fetchBkonLz4 } from './fetchBkonLz4';
import { fetchCdonLz4 } from './fetchCdonLz4';
export type TankFilterDefinitionCategory = 'clip';
@@ -34,6 +34,6 @@ export interface ConsumableDefinitions {
[key: string]: ConsumableEntry;
}
export const consumableDefinitions = fetchBkonLz4<ConsumableDefinitions>(
asset('definitions/consumables.bkon.lz4'),
export const consumableDefinitions = fetchCdonLz4<ConsumableDefinitions>(
asset('definitions/consumables.cdon.lz4'),
);
+3 -3
View File
@@ -1,5 +1,5 @@
import { asset } from './asset';
import { fetchBkonLz4 } from './fetchBkonLz4';
import { fetchCdonLz4 } from './fetchCdonLz4';
type EquipmentOptions = [number, number];
@@ -22,6 +22,6 @@ export interface EquipmentDefinitions {
};
}
export const equipmentDefinitions = fetchBkonLz4<EquipmentDefinitions>(
asset('definitions/equipment.bkon.lz4'),
export const equipmentDefinitions = fetchCdonLz4<EquipmentDefinitions>(
asset('definitions/equipment.cdon.lz4'),
);
@@ -1,6 +1,6 @@
import { superDecompress } from './superDecompress';
export async function fetchBkonLz4<Type>(url: string) {
export async function fetchCdonLz4<Type>(url: string) {
return await fetch(url, {
cache: 'no-cache',
}).then(async (response) => {
+3 -3
View File
@@ -1,6 +1,6 @@
import { Vector3Tuple } from 'three';
import { asset } from './asset';
import { fetchBkonLz4 } from './fetchBkonLz4';
import { fetchCdonLz4 } from './fetchCdonLz4';
export type ModelDefinitions = Record<number, ModelDefinition>;
@@ -54,6 +54,6 @@ export interface PitchLimits {
transition?: number;
}
export const modelDefinitions = fetchBkonLz4<ModelDefinitions>(
asset('definitions/models.bkon.lz4'),
export const modelDefinitions = fetchCdonLz4<ModelDefinitions>(
asset('definitions/models.cdon.lz4'),
);
+3 -3
View File
@@ -1,6 +1,6 @@
import { asset } from './asset';
import { TankFilterDefinition } from './consumableDefinitions';
import { fetchBkonLz4 } from './fetchBkonLz4';
import { fetchCdonLz4 } from './fetchCdonLz4';
export interface ProvisionEntry {
id: number;
@@ -14,6 +14,6 @@ export interface ProvisionDefinitions {
[key: string]: ProvisionEntry;
}
export const provisionDefinitions = fetchBkonLz4<ProvisionDefinitions>(
asset('definitions/provisions.bkon.lz4'),
export const provisionDefinitions = fetchCdonLz4<ProvisionDefinitions>(
asset('definitions/provisions.cdon.lz4'),
);
+2 -2
View File
@@ -1,8 +1,8 @@
import { compress } from 'lz4js';
import { BkonWriteStream } from '../streams/bkon';
import { CdonWriteStream } from '../streams/cdon';
export function superCompress(object: any) {
const write = new BkonWriteStream().bkon(object);
const write = new CdonWriteStream().cdon(object);
const compressed = compress(write.buffer);
return Buffer.from(compressed).toString('base64');
}
+3 -3
View File
@@ -1,8 +1,8 @@
import { decompress } from 'lz4js';
import { BkonReadStream } from '../streams/bkon';
import { CdonReadStream } from '../streams/cdon';
export function superDecompress<Type>(buffer: Buffer) {
const decompressed = Buffer.from(decompress(buffer));
const read = new BkonReadStream(decompressed);
return read.bkon() as Type;
const read = new CdonReadStream(decompressed);
return read.cdon() as Type;
}
+3 -3
View File
@@ -2,7 +2,7 @@ import { deburr } from 'lodash';
import { Vector2Tuple } from 'three';
import { TankType, TreeType } from '../../components/Tanks';
import { asset } from './asset';
import { fetchBkonLz4 } from './fetchBkonLz4';
import { fetchCdonLz4 } from './fetchCdonLz4';
export type ShellType = 'ap' | 'ap_cr' | 'hc' | 'he';
@@ -118,8 +118,8 @@ export const GUN_TYPE_NAMES: Record<GunDefinition['type'], string> = {
autoReloader: 'Auto reloader',
};
export const tankDefinitions = fetchBkonLz4<TankDefinitions>(
asset('definitions/tanks.bkon.lz4'),
export const tankDefinitions = fetchCdonLz4<TankDefinitions>(
asset('definitions/tanks.cdon.lz4'),
);
const entries = new Promise<TankDefinition[]>(async (resolve) => {
@@ -26,17 +26,17 @@ enum FastStringFormat {
Format32,
}
export type BkonValue =
export type CdonValue =
| null
| boolean
| number
| bigint
| string
| BkonValue[]
| { [key: string]: BkonValue };
| CdonValue[]
| { [key: string]: CdonValue };
export class BkonReadStream extends ReadStream {
bkon() {
export class CdonReadStream extends ReadStream {
cdon() {
this.magic();
const header = this.header();
const body = this.body(header.fastStringFormat, header.stringTable);
@@ -46,8 +46,8 @@ export class BkonReadStream extends ReadStream {
magic() {
const magic = this.utf8(4);
if (magic !== 'BKON') {
throw new Error(`Invalid Bkon magic number: "${magic}"`);
if (magic !== 'CDON') {
throw new Error(`Invalid Cdon magic number: "${magic}"`);
}
}
@@ -107,7 +107,7 @@ export class BkonReadStream extends ReadStream {
value(
fastStringFormat: FastStringFormat,
stringTable: Record<number, string>,
): BkonValue {
): CdonValue {
const type = this.uint8() as ValueType;
switch (type) {
@@ -177,7 +177,7 @@ export class BkonReadStream extends ReadStream {
const values = times(count, () =>
this.value(fastStringFormat, stringTable),
);
const object: Record<string, BkonValue> = {};
const object: Record<string, CdonValue> = {};
keys.forEach((string, index) => (object[string] = values[index]));
@@ -190,8 +190,8 @@ export class BkonReadStream extends ReadStream {
}
}
export class BkonWriteStream extends WriteStream {
bkon(object: BkonValue) {
export class CdonWriteStream extends WriteStream {
cdon(object: CdonValue) {
this.magic();
const header = this.header(object);
this.body(header.fastStringFormat, object, header.stringTable);
@@ -200,7 +200,7 @@ export class BkonWriteStream extends WriteStream {
body(
fastStringFormat: FastStringFormat,
object: BkonValue,
object: CdonValue,
stringTable: Map<string, number>,
) {
this.value(fastStringFormat, object, stringTable);
@@ -209,7 +209,7 @@ export class BkonWriteStream extends WriteStream {
value(
fastStringFormat: FastStringFormat,
object: BkonValue,
object: CdonValue,
stringTable: Map<string, number>,
) {
if (object === null || object === undefined) {
@@ -303,12 +303,12 @@ export class BkonWriteStream extends WriteStream {
}
}
header(object: BkonValue) {
header(object: CdonValue) {
this.uint16(1);
return this.stringTable(object);
}
stringTable(object: BkonValue) {
stringTable(object: CdonValue) {
const stringTable = this.buildStringTable(
this.collectStringCounts(object, new Map()),
);
@@ -343,7 +343,7 @@ export class BkonWriteStream extends WriteStream {
return stringTable;
}
collectStringCounts(object: BkonValue, stringCounts: Map<string, number>) {
collectStringCounts(object: CdonValue, stringCounts: Map<string, number>) {
if (typeof object === 'string') {
if (stringCounts.has(object)) {
stringCounts.set(object, stringCounts.get(object)! + 1);
@@ -367,6 +367,6 @@ export class BkonWriteStream extends WriteStream {
}
magic() {
this.utf8('BKON');
this.utf8('CDON');
}
}