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

Exception encoding nulled long #590

Closed
robin-anil opened this issue Dec 29, 2016 · 4 comments
Closed

Exception encoding nulled long #590

robin-anil opened this issue Dec 29, 2016 · 4 comments

Comments

@robin-anil
Copy link
Contributor

When encoding a long field set to null (which is typical of a JSON object), instead of the field being ignored the code throws an exception. I don't see a reason not to support the old behavior. Null or undefined override on a nulled field should ignore it from being encoded on the byte stream.

util.longNe = function longNe(val, lo, hi) {
    if (typeof val === "object") // Long-like, null is invalid and throws
        return val.low !== lo || val.high !== hi;
    var bits = util.LongBits.from(val);
    return bits.lo !== lo || bits.hi !== hi;
};

@robin-anil
Copy link
Contributor Author

This is a general comment about nulled fields in general. not just long.

@dcodeIO
Copy link
Member

dcodeIO commented Dec 29, 2016

There is no particularly important reason not to support ´null`. I just skipped it to save the additional assertion, i.e. here

("if(%s!==undefined&&util.longNe(%s,%d,%d))", ref, ref, field.defaultValue.low, field.defaultValue.high);

but I am also OK with supporting this again.

@robin-anil
Copy link
Contributor Author

Thank you! This is the last remaining issue(so far) in our migration from 5 to 6. Its coming along nicely.

@dcodeIO
Copy link
Member

dcodeIO commented Dec 29, 2016

I've added this for optional long fields especially now because any other objects would be messages, which default to null and thus are already checked against null where optional. Everything else should probably throw because it's either required or not an object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants