Skip to content

Commit acdfb0d

Browse files
committed
fix: incorrect decoding algorithm
1 parent e449abd commit acdfb0d

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/y-socket-io/y-socket-io.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as Y from 'yjs'
22
import * as AwarenessProtocol from 'y-protocols/awareness'
33
import * as promise from 'lib0/promise'
44
import * as encoding from 'lib0/encoding'
5+
import * as decoding from 'lib0/decoding'
56
import { assert } from 'lib0/testing.js'
67
import { User } from './user.js'
78
import * 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

Comments
 (0)