implement update logging

This commit is contained in:
Kevin Jahns
2020-12-16 21:25:00 +01:00
parent 22aef63d8a
commit 072947c0bb
3 changed files with 27 additions and 0 deletions

View File

@@ -2,6 +2,7 @@
import * as binary from 'lib0/binary.js'
import * as decoding from 'lib0/decoding.js'
import * as encoding from 'lib0/encoding.js'
import * as logging from 'lib0/logging.js'
import {
createID,
readItemContent,
@@ -82,6 +83,26 @@ export class LazyStructReader {
}
}
/**
* @param {Uint8Array} update
*
*/
export const logUpdate = update => logUpdateV2(update, UpdateDecoderV1)
/**
* @param {Uint8Array} update
* @param {typeof UpdateDecoderV2 | typeof UpdateDecoderV1} [YDecoder]
*
*/
export const logUpdateV2 = (update, YDecoder = UpdateDecoderV2) => {
const structs = []
const lazyDecoder = new LazyStructReader(new YDecoder(decoding.createDecoder(update)))
for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) {
structs.push(curr)
}
logging.print(structs)
}
export class LazyStructWriter {
/**
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder