Skip to content

Commit 484215b

Browse files
committed
ye
1 parent 3b563fc commit 484215b

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

src/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ export interface Namespace {
186186
): Connection;
187187
onSend(
188188
this: Namespace,
189-
handler: (data: unknown, name: string, player: Player | undefined) => unknown | undefined,
189+
handler: (data: unknown, name: string, player: Player | undefined) => unknown | DropSentinel | undefined,
190190
): () => void;
191191
onReceive(
192192
this: Namespace,
193-
handler: (data: unknown, name: string, player: Player | undefined) => unknown | undefined,
193+
handler: (data: unknown, name: string, player: Player | undefined) => unknown | DropSentinel | undefined,
194194
): () => void;
195195
disconnectAll(this: Namespace): void;
196196
destroy(this: Namespace): void;

test/codec/Map.test.luau

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,47 @@ describe("deltaMap", function(): ()
6161
c.write(ch, { a = 1, b = 2 })
6262
expect(ch.cursor):toBeLessThan(w1)
6363
end)
64+
it("numeric keys full round-trip", function(): ()
65+
Baseline.setReadKey(false)
66+
local c = Lync.deltaMap(Lync.u16, Lync.string)
67+
local r = roundTrip(c, { [1] = "one", [2] = "two", [300] = "three hundred" })
68+
expect(r[1]):toBe("one")
69+
expect(r[2]):toBe("two")
70+
expect(r[300]):toBe("three hundred")
71+
end)
72+
it("numeric keys unchanged is smaller", function(): ()
73+
Baseline.setReadKey(false)
74+
local c = Lync.deltaMap(Lync.u16, Lync.string)
75+
local ch = Channel.create()
76+
c.write(ch, { [1] = "one", [2] = "two" })
77+
local fullSize = ch.cursor
78+
ch.cursor = 0
79+
c.write(ch, { [1] = "one", [2] = "two" })
80+
expect(ch.cursor):toBeLessThan(fullSize)
81+
end)
82+
it("numeric keys upsert and remove", function(): ()
83+
Baseline.setReadKey(false)
84+
local c = Lync.deltaMap(Lync.u16, Lync.u8)
85+
local ch = Channel.create()
86+
87+
-- First write: full frame
88+
c.write(ch, { [10] = 100, [20] = 200 })
89+
local buf1 = buffer.create(ch.cursor)
90+
buffer.copy(buf1, 0, ch.buff, 0, ch.cursor)
91+
local r1 = c.read(buf1, 0, nil)
92+
expect(r1[10]):toBe(100)
93+
expect(r1[20]):toBe(200)
94+
95+
-- Second write: remove key 20, add key 30, change key 10
96+
ch.cursor = 0
97+
c.write(ch, { [10] = 50, [30] = 150 })
98+
local buf2 = buffer.create(ch.cursor)
99+
buffer.copy(buf2, 0, ch.buff, 0, ch.cursor)
100+
local r2 = c.read(buf2, 0, nil)
101+
expect(r2[10]):toBe(50)
102+
expect(r2[30]):toBe(150)
103+
expect(r2[20]):toBe(nil)
104+
end)
64105
end)
65106

66107
return nil

0 commit comments

Comments
 (0)