-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
I'm trying out the javascript generated flatbuffer code when I observe that optional string fields return null if the field doesn't exist while missing field for uint returns 0. I would think that it's useful to know when a field is null(missing) instead of returning 0 (which is a valid number).
Is this the intended behaviour? A quick check on the generated python and java classes shows that they return null for missing string fields but 0 on missing integers too.
To give a reduced use case, here's the idl.
table File {
size: uint;
}
root_type File;and the generated JS code.
/**
* @returns {number}
*/
File.prototype.size = function() {
var offset = this.bb.__offset(this.bb_pos, 6);
return offset ? this.bb.readUint32(this.bb_pos + offset) : 0;
};imho, i would prefer it to be the following (simply replace 0 with null when no offset is found)
File.prototype.size = function() {
var offset = this.bb.__offset(this.bb_pos, 6);
return offset ? this.bb.readUint32(this.bb_pos + offset) : null;
};cc @evanw (nice work on the js bindings btw!)
update: I observe a similar behaviour with arrays too. a missing field for [children] would return null in .children() but 0 in .childLength().