@@ -2,6 +2,7 @@ import * as Y from 'yjs'
22import * as AwarenessProtocol from 'y-protocols/awareness'
33import * as promise from 'lib0/promise'
44import * as encoding from 'lib0/encoding'
5+ import * as decoding from 'lib0/decoding'
56import { assert } from 'lib0/testing.js'
67import { User } from './user.js'
78import * as api from '../api.js'
@@ -349,32 +350,37 @@ export class YSocketIO {
349350 * @returns {{ type: EventType, message: Uint8Array } }
350351 */
351352 fromRedis ( message ) {
352- const msg = new Uint8Array ( message )
353- switch ( msg [ 0 ] ) {
353+ const decoder = decoding . createDecoder ( new Uint8Array ( message ) )
354+ const opt = decoding . readUint8 ( decoder )
355+
356+ switch ( opt ) {
354357 case protocol . messageSync : {
355- switch ( msg [ 1 ] ) {
358+ const syncStep = decoding . readUint8 ( decoder )
359+ const message = decoding . readVarUint8Array ( decoder )
360+ switch ( syncStep ) {
356361 case protocol . messageSyncStep1 :
357362 return {
358363 type : 'sync-step-1' ,
359- message : msg . slice ( 3 , msg . length )
364+ message
360365 }
361366 case protocol . messageSyncStep2 :
362367 return {
363368 type : 'sync-step-2' ,
364- message : msg . slice ( 3 , msg . length )
369+ message
365370 }
366371 case protocol . messageSyncUpdate :
367372 return {
368373 type : 'sync-update' ,
369- message : msg . slice ( 3 , msg . length )
374+ message
370375 }
371376 }
372377 break
373378 }
374379 case protocol . messageAwareness : {
380+ const message = decoding . readVarUint8Array ( decoder )
375381 return {
376382 type : 'awareness-update' ,
377- message : msg . slice ( 2 , msg . length )
383+ message
378384 }
379385 }
380386 }
0 commit comments