TinyVG / specification

The specification for TinyVG. This is the central authority for the file system
https://tinyvg.tech/
MIT License
246 stars 7 forks source link

VarUInt read() example is incorrect #26

Closed pluick closed 2 years ago

pluick commented 2 years ago

If I understand the VarUInt spec correctly, the 7th bit is set to indicate that this is the final bit of data. The example read() function seems to indicate the opposite (7th bit unset indicates the final bit). The example code should change from 0 -> 1, e.g.

if ((byte & 0x80) == 0)
    break;

change to

if ((byte & 0x80) == 1)
    break;
ikskuh commented 2 years ago

No, the VarUInt function is correct, what is the problem is my bad description of that decoding and a typo. The last byte must have 0x0? as the upper byte, not 0x8?

Also, your new code here is definitly wrong, and you should use 0x80 in the comparison

if ((byte & 0x80) == 0x80) // 1 is never a possible value here!
    break;
pluick commented 2 years ago

Oops, you are right about the bitmask.

So I was reading the description wrong and the changes should be something like this?:

-Bytes are read until the uppermost bit in the byte is set
+Bytes are read until the uppermost bit in the byte is not set

and about the final byte:

-This byte must always have the uppermost 4 bits set as 0b1000????.
+This byte must always have the uppermost 4 bits set as 0b0000????.
ikskuh commented 2 years ago

yep, that is correct

ikskuh commented 2 years ago

This should be fixed now