A tool to generate a JavaScript serializer from kaitai struct files.
This tool can be accessed either using require or via the CLI.
By running node main.js [input] [output]
with input being the ksy file and output being the name of the output js file, you can generate a serializer.
You can use the generate function by calling it with the contents of the ksy file. ks-serializer-js will then parse the yaml using js-yaml.
const Generator = require("../main")
fs.writeFileSync("./pngser.js", Generator(fs.readFileSync("./png.ksy", "utf8")))
Once you've got your serializer, you can require it, and call it with the deserialized object that the official deserializer gave you. You will get a buffer back.
const png = require("./png"); // The file generated with kaitai-struct-compiler
const pngser = require("./pngser") // The file generated with ks-serializer-js
const pngFile = fs.readFileSync("./test.png")
if(Buffer.compare(pngFile, pngser(new png(new kaitaiStream(pngFile)))) == 0) {
console.log("The files are the same!")
}
- All of the basic types
- Custom types
- Type switching
- Enums
- Repetitions
- Endians and string encodings
- Conditionals
- Value expressions
- Bitfields
- Imported types