jbos
v1.0.3
Published
JBOS -- the binary json alternative
Downloads
5
Readme
JBOS
JavaScript Binary Object Serializer
JBOS is a simple object serializer for JavaScript.
A usecase for JBOS is when you have an insane amount of data, it is more efficient than JSON.
API
Saving an object to a file
// Import JBOS
const jbos = require('jbos');
// Create an object
var serializeMe = {
array: [
true,
false,
"yes",
12,
345,
678.9,
null
]
};
// Serialize
jbos.writeFile("serialized.jbos", serializeMe);
Loading content from a file
// Import JBOS
const jbos = require('jbos');
// Serialize
var deserialized = jbos.readFile("serialized.jbos");
// Debug
console.log(deserialized);
Format Specification
⚠ TECHNICAL NONSENSE AHEAD - YOU DON'T NEED TO KNOW THIS TO USE IT ⚠
// Please note this is all little endian
// This is also pseudocode and problably not valid C
struct File {
byte[4] magic; // 4A 42 4F 53
Object object;
}
struct Object {
char type;
if (type == "G") {
// null
} else if (type == "D") {
// Dictionary
int itemCount;
DictionaryItem[itemCount] contents;
} else if (type == "A") {
// Array
int itemCount;
Object[itemCount] contents;
} else if (type == "S") {
// String
int stringLength;
char[stringLength] contents;
} else if (type == "N") {
// Number
float number;
} else if (type == "T") {
//true
} else if (type == "F") {
//false
} else if (type == "E") {
char[3] extensionId;
// No format extensions just yet
}
}
struct DictionaryItem {
int keyLength;
char[keyLength] key;
Object value;
}