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
r-tock opened this Issue Dec 29, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@r-tock
Contributor

r-tock commented Dec 29, 2016

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;
};

@r-tock

This comment has been minimized.

Contributor

r-tock commented Dec 29, 2016

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

@dcodeIO

This comment has been minimized.

Owner

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.

@dcodeIO dcodeIO added the enhancement label Dec 29, 2016

@r-tock

This comment has been minimized.

Contributor

r-tock commented Dec 29, 2016

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

dcodeIO added a commit that referenced this issue Dec 29, 2016

@dcodeIO

This comment has been minimized.

Owner

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.

@r-tock r-tock closed this Dec 29, 2016

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