add client-server updateCounter support to sync all persisted rooms

This commit is contained in:
Kevin Jahns
2018-06-04 17:35:39 +02:00
parent 6f9ae0c4fc
commit fb2f9bc493
11 changed files with 280 additions and 73 deletions

View File

@@ -46,6 +46,18 @@ export default class BinaryDecoder {
return this.uint8arr.length
}
/**
* Read `len` bytes as an ArrayBuffer.
*/
readArrayBuffer (len) {
const arrayBuffer = new Uint8Array(len)
const view = new Uint8Array(this.uint8arr.buffer, this.pos, len)
arrayBuffer.set(view)
this.pos += len
return arrayBuffer.buffer
}
/**
* Skip one byte, jump to the next position.
*/

View File

@@ -181,9 +181,13 @@ export default class BinaryEncoder {
* @param encoder The BinaryEncoder to be written.
*/
writeBinaryEncoder (encoder) {
this.writeArrayBuffer(encoder.createBuffer())
}
writeArrayBuffer (arrayBuffer) {
const prevBufferLen = this._currentBuffer.length
this._data.push(new Uint8Array(this._currentBuffer.buffer, 0, this._currentPos))
this._data.push(new Uint8Array(encoder.createBuffer()))
this._data.push(new Uint8Array(arrayBuffer))
this._currentBuffer = new Uint8Array(prevBufferLen)
this._currentPos = 0
}