From db53b6c720b7418ea322496ed85e15a1dcfa35c2 Mon Sep 17 00:00:00 2001 From: Ulf Karlsson Date: Fri, 4 Feb 2022 13:47:57 +0100 Subject: [PATCH 1/2] Add decode methods --- src/index.js | 2 ++ src/utils/updates.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/index.js b/src/index.js index 07bc2044..1a82a479 100644 --- a/src/index.js +++ b/src/index.js @@ -67,6 +67,8 @@ export { decodeStateVector, logUpdate, logUpdateV2, + decodeUpdate, + decodeUpdateV2, relativePositionToJSON, isDeleted, isParentOf, diff --git a/src/utils/updates.js b/src/utils/updates.js index fa6add00..d62e58fa 100644 --- a/src/utils/updates.js +++ b/src/utils/updates.js @@ -112,6 +112,31 @@ export const logUpdateV2 = (update, YDecoder = UpdateDecoderV2) => { logging.print('DeleteSet: ', ds) } +/** + * @param {Uint8Array} update + * + */ +export const decodeUpdate = (update) => decodeUpdateV2(update, UpdateDecoderV1) + +/** + * @param {Uint8Array} update + * @param {typeof UpdateDecoderV2 | typeof UpdateDecoderV1} [YDecoder] + * + */ +export const decodeUpdateV2 = (update, YDecoder = UpdateDecoderV2) => { + const structs = [] + const updateDecoder = new UpdateDecoderV1(decoding.createDecoder(update)) + const lazyDecoder = new LazyStructReader(updateDecoder, false) + for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) { + structs.push(curr) + curr.info + } + return { + 'structs': structs, + 'ds': readDeleteSet(updateDecoder), + } +} + export class LazyStructWriter { /** * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder From 8678ef62d64b8efc15164c46c943f7f0f57b113e Mon Sep 17 00:00:00 2001 From: Ulf Karlsson Date: Mon, 7 Feb 2022 20:00:10 +0100 Subject: [PATCH 2/2] Remove curr.info --- src/utils/updates.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils/updates.js b/src/utils/updates.js index d62e58fa..83ac18b3 100644 --- a/src/utils/updates.js +++ b/src/utils/updates.js @@ -129,7 +129,6 @@ export const decodeUpdateV2 = (update, YDecoder = UpdateDecoderV2) => { const lazyDecoder = new LazyStructReader(updateDecoder, false) for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) { structs.push(curr) - curr.info } return { 'structs': structs,