Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested object constructors #92

Open
ppslim opened this issue Feb 18, 2019 · 0 comments
Open

Nested object constructors #92

ppslim opened this issue Feb 18, 2019 · 0 comments

Comments

@ppslim
Copy link

ppslim commented Feb 18, 2019

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant