You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
After writing the content to IntDiffOptRleEncoder (also UintOptRleEncoder, IncUintOptRleEncoder), when reading the content with toUint8Array(), the content is different each time due to flush.
Expected behavior
Since toUint8Array() is obviously a function for reading values, its contents should not change with each call.
To fix IntDiffOptRleEncoder should have a flag like mutated. In that case, the implementation would be as follows
exportclassIntDiffOptRleEncoder{constructor(){this.encoder=newEncoder()/** * @type {number} */this.s=0this.count=0this.diff=0this.mutated=false}/** * @param {number} v */write(v){this.mutated=trueif(this.diff===v-this.s){this.s=vthis.count++}else{flushIntDiffOptRleEncoder(this)this.count=1this.diff=v-this.sthis.s=v}}toUint8Array(){if(this.mutated){flushIntDiffOptRleEncoder(this)this.mutated=false}returntoUint8Array(this.encoder)}}
Appendices
In yjs, there is no part of IntDiffOptRleEncoder that calls toUint8Array() twice.
I also confirmed that IntDiffOptRleEncoder with this modification passes all tests in yjs.
(I am personally working on yjs for Swift yswift. I discovered this in debugging).
The text was updated successfully, but these errors were encountered:
I should add more documentation on this. The idea is that you call toUint8Array only once to serialize the data. Serializing it several times is not supposed to work. It's also not supported by the other RLE encoders - to decrease complexity. Instead, you could create a new RLE encoder if you want to encode new data.
What's the use-case for calling toUint8Array twice?
Describe the bug
After writing the content to
IntDiffOptRleEncoder
(alsoUintOptRleEncoder
,IncUintOptRleEncoder
), when reading the content withtoUint8Array()
, the content is different each time due to flush.Expected behavior
Since
toUint8Array()
is obviously a function for reading values, its contents should not change with each call.To fix
IntDiffOptRleEncoder
should have a flag like mutated. In that case, the implementation would be as followsAppendices
In yjs, there is no part of
IntDiffOptRleEncoder
that callstoUint8Array()
twice.I also confirmed that
IntDiffOptRleEncoder
with this modification passes all tests in yjs.(I am personally working on yjs for Swift yswift. I discovered this in debugging).
The text was updated successfully, but these errors were encountered: