@axpecter/lync 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -2
- package/package.json +3 -2
- package/src/Types.luau +13 -1
- package/src/api/Group.luau +35 -28
- package/src/api/Namespace.luau +107 -89
- package/src/api/Packet.luau +69 -51
- package/src/api/Query.luau +101 -95
- package/src/api/Scope.luau +32 -18
- package/src/api/Signal.luau +78 -56
- package/src/codec/Base.luau +17 -17
- package/src/codec/composite/Array.luau +74 -74
- package/src/codec/composite/Map.luau +80 -80
- package/src/codec/composite/Optional.luau +14 -14
- package/src/codec/composite/Shared.luau +35 -35
- package/src/codec/composite/Struct.luau +108 -108
- package/src/codec/composite/Tagged.luau +71 -71
- package/src/codec/composite/Tuple.luau +35 -35
- package/src/codec/datatype/Buffer.luau +18 -18
- package/src/codec/datatype/CFrame.luau +24 -24
- package/src/codec/datatype/Color.luau +8 -12
- package/src/codec/datatype/Instance.luau +13 -13
- package/src/codec/datatype/IntVector.luau +17 -17
- package/src/codec/datatype/NumberRange.luau +7 -7
- package/src/codec/datatype/Ray.luau +16 -16
- package/src/codec/datatype/Rect.luau +13 -13
- package/src/codec/datatype/Region.luau +32 -36
- package/src/codec/datatype/Sequence.luau +41 -41
- package/src/codec/datatype/String.luau +28 -28
- package/src/codec/datatype/UDim.luau +17 -17
- package/src/codec/datatype/Vector.luau +14 -18
- package/src/codec/meta/Auto.luau +75 -73
- package/src/codec/meta/Bitfield.luau +46 -46
- package/src/codec/meta/Custom.luau +7 -7
- package/src/codec/meta/Enum.luau +25 -25
- package/src/codec/meta/Nothing.luau +3 -3
- package/src/codec/meta/Quantized.luau +63 -60
- package/src/codec/meta/Unknown.luau +11 -11
- package/src/codec/primitive/Bool.luau +12 -12
- package/src/codec/primitive/Float16.luau +28 -28
- package/src/codec/primitive/Number.luau +41 -41
- package/src/codec/primitive/Varint.luau +19 -19
- package/src/init.luau +81 -61
- package/src/internal/Baseline.luau +7 -7
- package/src/internal/Channel.luau +56 -56
- package/src/internal/Middleware.luau +29 -29
- package/src/internal/Pool.luau +15 -15
- package/src/internal/Registry.luau +19 -19
- package/src/transport/Bridge.luau +17 -17
- package/src/transport/Client.luau +46 -46
- package/src/transport/Gate.luau +56 -64
- package/src/transport/Reader.luau +34 -34
- package/src/transport/Server.luau +89 -89
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
--!native
|
|
3
3
|
-- array and deltaArray codecs.
|
|
4
4
|
|
|
5
|
-
local Baseline = require
|
|
6
|
-
local Channel = require
|
|
7
|
-
local Shared = require
|
|
8
|
-
local Types = require
|
|
9
|
-
local Varint = require
|
|
5
|
+
local Baseline = require(script.Parent.Parent.Parent.internal.Baseline)
|
|
6
|
+
local Channel = require(script.Parent.Parent.Parent.internal.Channel)
|
|
7
|
+
local Shared = require(script.Parent.Shared)
|
|
8
|
+
local Types = require(script.Parent.Parent.Parent.Types)
|
|
9
|
+
local Varint = require(script.Parent.Parent.primitive.Varint)
|
|
10
10
|
|
|
11
11
|
type ChannelState = Types.ChannelState
|
|
12
12
|
type Codec<T> = Types.Codec<T>
|
|
@@ -21,12 +21,12 @@ local FLAG_DELTA = Shared.FLAG_DELTA
|
|
|
21
21
|
local FLAG_FULL = Shared.FLAG_FULL
|
|
22
22
|
local FLAG_UNCHANGED = Shared.FLAG_UNCHANGED
|
|
23
23
|
|
|
24
|
-
-- Public
|
|
24
|
+
-- Public --------------------------------------------------------------
|
|
25
25
|
|
|
26
26
|
local Array = {}
|
|
27
27
|
|
|
28
|
-
function Array.deltaArray
|
|
29
|
-
local deltaId = Shared.allocDeltaId
|
|
28
|
+
function Array.deltaArray(element: Codec<any>, maxCount: number?): Codec<{ any }>
|
|
29
|
+
local deltaId = Shared.allocDeltaId()
|
|
30
30
|
|
|
31
31
|
local writeElement = element.write
|
|
32
32
|
local readElement = element.read
|
|
@@ -36,31 +36,31 @@ function Array.deltaArray (element: Codec<any>, maxCount: number?): Codec<{ any
|
|
|
36
36
|
local elemWrite = internal._directWrite
|
|
37
37
|
local elemRead = internal._directRead
|
|
38
38
|
|
|
39
|
-
return table.freeze
|
|
39
|
+
return table.freeze({
|
|
40
40
|
_isDelta = true,
|
|
41
41
|
|
|
42
|
-
write = function
|
|
42
|
+
write = function(ch: ChannelState, value: { any }): ()
|
|
43
43
|
local len = #value
|
|
44
44
|
local cache = ch.deltas[deltaId] :: { raw: buffer, bounds: { number }, len: number }?
|
|
45
|
-
local scratch = acquireScratch
|
|
45
|
+
local scratch = acquireScratch()
|
|
46
46
|
|
|
47
|
-
local bounds = table.create
|
|
47
|
+
local bounds = table.create(len + 1)
|
|
48
48
|
bounds[1] = 0
|
|
49
49
|
|
|
50
50
|
if elemWrite and elemSize then
|
|
51
51
|
local totalBytes = len * elemSize
|
|
52
|
-
alloc
|
|
52
|
+
alloc(scratch, totalBytes)
|
|
53
53
|
local b = scratch.buff
|
|
54
54
|
local c = 0
|
|
55
55
|
for i = 1, len do
|
|
56
|
-
elemWrite
|
|
56
|
+
elemWrite(b, c, value[i])
|
|
57
57
|
c += elemSize
|
|
58
58
|
bounds[i + 1] = c
|
|
59
59
|
end
|
|
60
60
|
scratch.cursor = totalBytes
|
|
61
61
|
else
|
|
62
62
|
for i = 1, len do
|
|
63
|
-
writeElement
|
|
63
|
+
writeElement(scratch, value[i])
|
|
64
64
|
bounds[i + 1] = scratch.cursor
|
|
65
65
|
end
|
|
66
66
|
end
|
|
@@ -68,18 +68,18 @@ function Array.deltaArray (element: Codec<any>, maxCount: number?): Codec<{ any
|
|
|
68
68
|
local scratchTotal = scratch.cursor
|
|
69
69
|
|
|
70
70
|
if not cache or cache.len ~= len then
|
|
71
|
-
alloc
|
|
72
|
-
buffer.writeu8
|
|
71
|
+
alloc(ch, 1)
|
|
72
|
+
buffer.writeu8(ch.buff, ch.cursor, FLAG_FULL)
|
|
73
73
|
ch.cursor += 1
|
|
74
|
-
Varint.write
|
|
74
|
+
Varint.write(ch, len)
|
|
75
75
|
|
|
76
|
-
alloc
|
|
77
|
-
buffer.copy
|
|
76
|
+
alloc(ch, scratchTotal)
|
|
77
|
+
buffer.copy(ch.buff, ch.cursor, scratch.buff, 0, scratchTotal)
|
|
78
78
|
ch.cursor += scratchTotal
|
|
79
79
|
else
|
|
80
80
|
local cacheRaw = cache.raw
|
|
81
81
|
local cacheBds = cache.bounds
|
|
82
|
-
local dirty = table.create
|
|
82
|
+
local dirty = table.create(len)
|
|
83
83
|
local dirtyN = 0
|
|
84
84
|
|
|
85
85
|
for i = 1, len do
|
|
@@ -90,7 +90,7 @@ function Array.deltaArray (element: Codec<any>, maxCount: number?): Codec<{ any
|
|
|
90
90
|
|
|
91
91
|
if
|
|
92
92
|
newLen ~= oldLen
|
|
93
|
-
or not rangeEqual
|
|
93
|
+
or not rangeEqual(scratch.buff, newOff, cacheRaw, oldOff, newLen)
|
|
94
94
|
then
|
|
95
95
|
dirtyN += 1
|
|
96
96
|
dirty[dirtyN] = i
|
|
@@ -98,111 +98,111 @@ function Array.deltaArray (element: Codec<any>, maxCount: number?): Codec<{ any
|
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
if dirtyN == 0 then
|
|
101
|
-
alloc
|
|
102
|
-
buffer.writeu8
|
|
101
|
+
alloc(ch, 1)
|
|
102
|
+
buffer.writeu8(ch.buff, ch.cursor, FLAG_UNCHANGED)
|
|
103
103
|
ch.cursor += 1
|
|
104
|
-
releaseScratch
|
|
104
|
+
releaseScratch()
|
|
105
105
|
return
|
|
106
106
|
end
|
|
107
107
|
|
|
108
|
-
alloc
|
|
109
|
-
buffer.writeu8
|
|
108
|
+
alloc(ch, 1)
|
|
109
|
+
buffer.writeu8(ch.buff, ch.cursor, FLAG_DELTA)
|
|
110
110
|
ch.cursor += 1
|
|
111
|
-
Varint.write
|
|
111
|
+
Varint.write(ch, dirtyN)
|
|
112
112
|
|
|
113
113
|
for j = 1, dirtyN do
|
|
114
114
|
local i = dirty[j]
|
|
115
115
|
local newOff = bounds[i]
|
|
116
116
|
local newLen = bounds[i + 1] - newOff
|
|
117
117
|
|
|
118
|
-
Varint.write
|
|
119
|
-
alloc
|
|
120
|
-
buffer.copy
|
|
118
|
+
Varint.write(ch, i - 1)
|
|
119
|
+
alloc(ch, newLen)
|
|
120
|
+
buffer.copy(ch.buff, ch.cursor, scratch.buff, newOff, newLen)
|
|
121
121
|
ch.cursor += newLen
|
|
122
122
|
end
|
|
123
123
|
end
|
|
124
124
|
|
|
125
|
-
local rawBuf = buffer.create
|
|
126
|
-
buffer.copy
|
|
125
|
+
local rawBuf = buffer.create(scratchTotal)
|
|
126
|
+
buffer.copy(rawBuf, 0, scratch.buff, 0, scratchTotal)
|
|
127
127
|
|
|
128
|
-
table.freeze
|
|
128
|
+
table.freeze(bounds)
|
|
129
129
|
ch.deltas[deltaId] = { raw = rawBuf, bounds = bounds, len = len }
|
|
130
|
-
releaseScratch
|
|
130
|
+
releaseScratch()
|
|
131
131
|
end,
|
|
132
132
|
|
|
133
|
-
read = function
|
|
134
|
-
local flag = buffer.readu8
|
|
133
|
+
read = function(src: buffer, pos: number, refs: { Instance }?): ({ any }, number)
|
|
134
|
+
local flag = buffer.readu8(src, pos)
|
|
135
135
|
local absPos = pos + 1
|
|
136
136
|
|
|
137
137
|
if flag == FLAG_UNCHANGED then
|
|
138
|
-
local cache = Baseline.getCache
|
|
139
|
-
return if cache then table.clone
|
|
138
|
+
local cache = Baseline.getCache(deltaId)
|
|
139
|
+
return if cache then table.clone(cache) else {}, 1
|
|
140
140
|
end
|
|
141
141
|
|
|
142
142
|
if flag == FLAG_FULL then
|
|
143
|
-
local len, lenBytes = Varint.read
|
|
143
|
+
local len, lenBytes = Varint.read(src, absPos)
|
|
144
144
|
absPos += lenBytes
|
|
145
145
|
|
|
146
146
|
if maxCount and len > maxCount then
|
|
147
|
-
error
|
|
147
|
+
error(`[Lync] Array count {len} exceeds max {maxCount}`)
|
|
148
148
|
end
|
|
149
149
|
|
|
150
|
-
local result = table.create
|
|
150
|
+
local result = table.create(len)
|
|
151
151
|
|
|
152
152
|
if elemRead and elemSize then
|
|
153
153
|
for i = 1, len do
|
|
154
|
-
result[i] = elemRead
|
|
154
|
+
result[i] = elemRead(src, absPos)
|
|
155
155
|
absPos += elemSize
|
|
156
156
|
end
|
|
157
157
|
else
|
|
158
158
|
for i = 1, len do
|
|
159
|
-
local val, n = readElement
|
|
159
|
+
local val, n = readElement(src, absPos, refs)
|
|
160
160
|
result[i] = val
|
|
161
161
|
absPos += n
|
|
162
162
|
end
|
|
163
163
|
end
|
|
164
164
|
|
|
165
|
-
Baseline.setCache
|
|
165
|
+
Baseline.setCache(deltaId, result)
|
|
166
166
|
return result, absPos - pos
|
|
167
167
|
end
|
|
168
168
|
|
|
169
|
-
local cache = Baseline.getCache
|
|
170
|
-
local result = if cache then table.clone
|
|
169
|
+
local cache = Baseline.getCache(deltaId) :: { any }?
|
|
170
|
+
local result = if cache then table.clone(cache) else {}
|
|
171
171
|
|
|
172
|
-
local dirtyN, dnBytes = Varint.read
|
|
172
|
+
local dirtyN, dnBytes = Varint.read(src, absPos)
|
|
173
173
|
absPos += dnBytes
|
|
174
174
|
|
|
175
175
|
for _ = 1, dirtyN do
|
|
176
|
-
local idx, idxBytes = Varint.read
|
|
176
|
+
local idx, idxBytes = Varint.read(src, absPos)
|
|
177
177
|
absPos += idxBytes
|
|
178
178
|
|
|
179
179
|
if elemRead and elemSize then
|
|
180
|
-
result[idx + 1] = elemRead
|
|
180
|
+
result[idx + 1] = elemRead(src, absPos)
|
|
181
181
|
absPos += elemSize
|
|
182
182
|
else
|
|
183
|
-
local val, n = readElement
|
|
183
|
+
local val, n = readElement(src, absPos, refs)
|
|
184
184
|
result[idx + 1] = val
|
|
185
185
|
absPos += n
|
|
186
186
|
end
|
|
187
187
|
end
|
|
188
188
|
|
|
189
|
-
Baseline.setCache
|
|
189
|
+
Baseline.setCache(deltaId, result)
|
|
190
190
|
return result, absPos - pos
|
|
191
191
|
end,
|
|
192
192
|
})
|
|
193
193
|
end
|
|
194
194
|
|
|
195
|
-
function Array.array
|
|
195
|
+
function Array.array(element: Codec<any>, maxCount: number?): Codec<{ any }>
|
|
196
196
|
local internal = element :: InternalCodec<any>
|
|
197
197
|
local elementSize = internal._size
|
|
198
198
|
local directWrite = internal._directWrite
|
|
199
199
|
local directRead = internal._directRead
|
|
200
200
|
|
|
201
201
|
if elementSize and directWrite and directRead then
|
|
202
|
-
return table.freeze
|
|
203
|
-
write = function
|
|
202
|
+
return table.freeze({
|
|
203
|
+
write = function(ch: ChannelState, value: { any }): ()
|
|
204
204
|
local len = #value
|
|
205
|
-
Varint.write
|
|
205
|
+
Varint.write(ch, len)
|
|
206
206
|
if len == 0 then
|
|
207
207
|
return
|
|
208
208
|
end
|
|
@@ -210,28 +210,28 @@ function Array.array (element: Codec<any>, maxCount: number?): Codec<{ any }>
|
|
|
210
210
|
local totalBytes = len * elementSize
|
|
211
211
|
local c = ch.cursor
|
|
212
212
|
if c + totalBytes > ch.size then
|
|
213
|
-
alloc
|
|
213
|
+
alloc(ch, totalBytes)
|
|
214
214
|
end
|
|
215
215
|
|
|
216
216
|
local b = ch.buff
|
|
217
217
|
for i = 1, len do
|
|
218
|
-
directWrite
|
|
218
|
+
directWrite(b, c, value[i])
|
|
219
219
|
c += elementSize
|
|
220
220
|
end
|
|
221
221
|
ch.cursor = c
|
|
222
222
|
end,
|
|
223
|
-
read = function
|
|
224
|
-
local len, lenBytes = Varint.read
|
|
223
|
+
read = function(src: buffer, pos: number, _refs: { Instance }?): ({ any }, number)
|
|
224
|
+
local len, lenBytes = Varint.read(src, pos)
|
|
225
225
|
|
|
226
226
|
if maxCount and len > maxCount then
|
|
227
|
-
error
|
|
227
|
+
error(`[Lync] Array count {len} exceeds max {maxCount}`)
|
|
228
228
|
end
|
|
229
229
|
|
|
230
|
-
local result = table.create
|
|
230
|
+
local result = table.create(len)
|
|
231
231
|
local c = pos + lenBytes
|
|
232
232
|
|
|
233
233
|
for i = 1, len do
|
|
234
|
-
result[i] = directRead
|
|
234
|
+
result[i] = directRead(src, c)
|
|
235
235
|
c += elementSize
|
|
236
236
|
end
|
|
237
237
|
|
|
@@ -243,29 +243,29 @@ function Array.array (element: Codec<any>, maxCount: number?): Codec<{ any }>
|
|
|
243
243
|
local writeElement = element.write
|
|
244
244
|
local readElement = element.read
|
|
245
245
|
|
|
246
|
-
return table.freeze
|
|
247
|
-
write = function
|
|
246
|
+
return table.freeze({
|
|
247
|
+
write = function(ch: ChannelState, value: { any }): ()
|
|
248
248
|
local len = #value
|
|
249
|
-
Varint.write
|
|
249
|
+
Varint.write(ch, len)
|
|
250
250
|
if elementSize and len > 0 then
|
|
251
|
-
alloc
|
|
251
|
+
alloc(ch, len * elementSize)
|
|
252
252
|
end
|
|
253
253
|
for i = 1, len do
|
|
254
|
-
writeElement
|
|
254
|
+
writeElement(ch, value[i])
|
|
255
255
|
end
|
|
256
256
|
end,
|
|
257
|
-
read = function
|
|
258
|
-
local len, lenBytes = Varint.read
|
|
257
|
+
read = function(src: buffer, pos: number, refs: { Instance }?): ({ any }, number)
|
|
258
|
+
local len, lenBytes = Varint.read(src, pos)
|
|
259
259
|
|
|
260
260
|
if maxCount and len > maxCount then
|
|
261
|
-
error
|
|
261
|
+
error(`[Lync] Array count {len} exceeds max {maxCount}`)
|
|
262
262
|
end
|
|
263
263
|
|
|
264
|
-
local result = table.create
|
|
264
|
+
local result = table.create(len)
|
|
265
265
|
local absPos = pos + lenBytes
|
|
266
266
|
|
|
267
267
|
for i = 1, len do
|
|
268
|
-
local value, n = readElement
|
|
268
|
+
local value, n = readElement(src, absPos, refs)
|
|
269
269
|
result[i] = value
|
|
270
270
|
absPos += n
|
|
271
271
|
end
|
|
@@ -275,4 +275,4 @@ function Array.array (element: Codec<any>, maxCount: number?): Codec<{ any }>
|
|
|
275
275
|
})
|
|
276
276
|
end
|
|
277
277
|
|
|
278
|
-
return table.freeze
|
|
278
|
+
return table.freeze(Array)
|