binary-parser
binary-parser copied to clipboard
Nested object constructors
Are nested parsers intended to function with the constructor?
The following sample. Parsing from male works, I get a MaleOBJ instance.
But nesting male in male_nesteda, the constructor is not used.
const Parser = require("binary-parser").Parser;
function MaleOBJ() {
this.name = "";
};
MaleOBJ.prototype.toString = function() {
return "[object MaleOBJ]";
};
var male = new Parser()
.create(MaleOBJ)
.string("name", {
zeroTerminated: true
});
var nested_malea = new Parser()
.string("other_name", {
zeroTerminated: true
})
.nest("other", {
type: male
});
var buffer = Buffer.from("Alpha male\0John Doe\0");
var denested = male.parse(buffer);
console.log(typeof denested);
console.log(denested);
var nesteda = nested_malea.parse(buffer);
console.log(typeof nesteda);
console.log(nesteda);