Implement experimental new encoder 🚀

This commit is contained in:
Kevin Jahns
2020-07-12 18:25:45 +02:00
parent e31e968f0d
commit 6c2cf0f769
36 changed files with 1224 additions and 336 deletions

View File

@@ -1,12 +1,9 @@
import {
addToDeleteSet,
StructStore, Item, Transaction // eslint-disable-line
AbstractUpdateDecoder, AbstractUpdateEncoder, StructStore, Item, Transaction // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
export class ContentDeleted {
/**
* @param {number} len
@@ -67,7 +64,7 @@ export class ContentDeleted {
* @param {Item} item
*/
integrate (transaction, item) {
addToDeleteSet(transaction.deleteSet, item.id, this.len)
addToDeleteSet(transaction.deleteSet, item.id.client, item.id.clock, this.len)
item.markDeleted()
}
@@ -80,11 +77,11 @@ export class ContentDeleted {
*/
gc (store) {}
/**
* @param {encoding.Encoder} encoder
* @param {AbstractUpdateEncoder} encoder
* @param {number} offset
*/
write (encoder, offset) {
encoding.writeVarUint(encoder, this.len - offset)
encoder.writeLen(this.len - offset)
}
/**
@@ -98,7 +95,7 @@ export class ContentDeleted {
/**
* @private
*
* @param {decoding.Decoder} decoder
* @param {AbstractUpdateDecoder} decoder
* @return {ContentDeleted}
*/
export const readContentDeleted = decoder => new ContentDeleted(decoding.readVarUint(decoder))
export const readContentDeleted = decoder => new ContentDeleted(decoder.readLen())