beve-org / beve

High performance, tagged binary data specification
MIT License
48 stars 1 forks source link

TypeError: Cannot convert undefined or null to object #7

Open meftunca opened 1 week ago

meftunca commented 1 week ago

JSON and most languages do not support undefined values, and this is how the write_beve function on beve js throws an error for the undefined value passed to it. This is a potential bug for the js. Something needs to be done about this.

Suggestion,

  1. remove Object values with undefined values (like browsers do in rest api requests)
  2. We can convert Array elements with undefined value to null

I was able to solve the problem by adding a new "if" branch under write_value.

else if (value === null) {
        let header = 0;
        header |= 0b00000000;
        writer.append_uint8(header);
    } 
stephenberry commented 1 week ago

I like your suggestion, I think undefined object values should be removed and array elements changed to null. Good thoughts.