@axpecter/lync 1.4.3 → 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 +1 -1
- 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,10 +2,10 @@
|
|
|
2
2
|
--!native
|
|
3
3
|
-- struct and deltaStruct codecs.
|
|
4
4
|
|
|
5
|
-
local Baseline = require
|
|
6
|
-
local Channel = require
|
|
7
|
-
local Shared = require
|
|
8
|
-
local Types = 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
9
|
|
|
10
10
|
type ChannelState = Types.ChannelState
|
|
11
11
|
type Codec<T> = Types.Codec<T>
|
|
@@ -35,25 +35,25 @@ type DeltaCache = {
|
|
|
35
35
|
total: number,
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
-- Public
|
|
38
|
+
-- Public --------------------------------------------------------------
|
|
39
39
|
|
|
40
40
|
local Struct = {}
|
|
41
41
|
|
|
42
|
-
function Struct.struct
|
|
43
|
-
local dataKeys, dataCodecs, boolKeys = extractFields
|
|
42
|
+
function Struct.struct(schema: { [string]: Codec<any> }): Codec<any>
|
|
43
|
+
local dataKeys, dataCodecs, boolKeys = extractFields(schema)
|
|
44
44
|
|
|
45
45
|
local dataCount = #dataKeys
|
|
46
46
|
local boolCount = #boolKeys
|
|
47
|
-
local boolByteCount = ceil
|
|
47
|
+
local boolByteCount = ceil(boolCount / 8)
|
|
48
48
|
local hasBools = boolCount > 0
|
|
49
49
|
|
|
50
50
|
local canDirect = true
|
|
51
51
|
local fixedSize = boolByteCount
|
|
52
52
|
local isAllFixed = true
|
|
53
53
|
|
|
54
|
-
local directWrites = table.create
|
|
55
|
-
local directReads = table.create
|
|
56
|
-
local fieldSizes = table.create
|
|
54
|
+
local directWrites = table.create(dataCount) :: { any }
|
|
55
|
+
local directReads = table.create(dataCount) :: { any }
|
|
56
|
+
local fieldSizes = table.create(dataCount) :: { number }
|
|
57
57
|
|
|
58
58
|
for i = 1, dataCount do
|
|
59
59
|
local codec = dataCodecs[i] :: InternalCodec<any>
|
|
@@ -78,106 +78,106 @@ function Struct.struct (schema: { [string]: Codec<any> }): Codec<any>
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
if canDirect and isAllFixed then
|
|
81
|
-
table.freeze
|
|
82
|
-
table.freeze
|
|
83
|
-
table.freeze
|
|
81
|
+
table.freeze(directWrites)
|
|
82
|
+
table.freeze(directReads)
|
|
83
|
+
table.freeze(fieldSizes)
|
|
84
84
|
|
|
85
|
-
local function directWriteBody
|
|
85
|
+
local function directWriteBody(b: buffer, c: number, value: any): ()
|
|
86
86
|
for i = 1, dataCount do
|
|
87
|
-
directWrites[i]
|
|
87
|
+
directWrites[i](b, c, value[dataKeys[i]])
|
|
88
88
|
c += fieldSizes[i]
|
|
89
89
|
end
|
|
90
90
|
if hasBools then
|
|
91
91
|
for byteIdx = 0, boolByteCount - 1 do
|
|
92
92
|
local packed = 0
|
|
93
93
|
local base = byteIdx * 8
|
|
94
|
-
local limit = min
|
|
94
|
+
local limit = min(8, boolCount - base)
|
|
95
95
|
for bit = 0, limit - 1 do
|
|
96
96
|
if value[boolKeys[base + bit + 1]] then
|
|
97
|
-
packed = bor
|
|
97
|
+
packed = bor(packed, lshift(1, bit))
|
|
98
98
|
end
|
|
99
99
|
end
|
|
100
|
-
buffer.writeu8
|
|
100
|
+
buffer.writeu8(b, c + byteIdx, packed)
|
|
101
101
|
end
|
|
102
102
|
end
|
|
103
103
|
end
|
|
104
104
|
|
|
105
|
-
local function directReadBody
|
|
105
|
+
local function directReadBody(b: buffer, pos: number): any
|
|
106
106
|
local result = {}
|
|
107
107
|
local c = pos
|
|
108
108
|
for i = 1, dataCount do
|
|
109
|
-
result[dataKeys[i]] = directReads[i]
|
|
109
|
+
result[dataKeys[i]] = directReads[i](b, c)
|
|
110
110
|
c += fieldSizes[i]
|
|
111
111
|
end
|
|
112
112
|
if hasBools then
|
|
113
113
|
for byteIdx = 0, boolByteCount - 1 do
|
|
114
|
-
local byte = buffer.readu8
|
|
114
|
+
local byte = buffer.readu8(b, c + byteIdx)
|
|
115
115
|
local base = byteIdx * 8
|
|
116
|
-
local limit = min
|
|
116
|
+
local limit = min(8, boolCount - base)
|
|
117
117
|
for bit = 0, limit - 1 do
|
|
118
|
-
result[boolKeys[base + bit + 1]] = band
|
|
118
|
+
result[boolKeys[base + bit + 1]] = band(byte, lshift(1, bit)) ~= 0
|
|
119
119
|
end
|
|
120
120
|
end
|
|
121
121
|
end
|
|
122
122
|
return result
|
|
123
123
|
end
|
|
124
124
|
|
|
125
|
-
return table.freeze
|
|
125
|
+
return table.freeze({
|
|
126
126
|
_size = fixedSize,
|
|
127
127
|
_directWrite = directWriteBody,
|
|
128
128
|
_directRead = directReadBody,
|
|
129
129
|
|
|
130
|
-
write = function
|
|
130
|
+
write = function(ch: ChannelState, value: any): ()
|
|
131
131
|
local c = ch.cursor
|
|
132
132
|
if c + fixedSize > ch.size then
|
|
133
|
-
alloc
|
|
133
|
+
alloc(ch, fixedSize)
|
|
134
134
|
end
|
|
135
|
-
directWriteBody
|
|
135
|
+
directWriteBody(ch.buff, c, value)
|
|
136
136
|
ch.cursor = c + fixedSize
|
|
137
137
|
end,
|
|
138
|
-
read = function
|
|
139
|
-
return directReadBody
|
|
138
|
+
read = function(src: buffer, pos: number, _refs: { Instance }?): (any, number)
|
|
139
|
+
return directReadBody(src, pos), fixedSize
|
|
140
140
|
end,
|
|
141
141
|
})
|
|
142
142
|
end
|
|
143
143
|
|
|
144
|
-
local writeFns = table.create
|
|
145
|
-
local readFns = table.create
|
|
144
|
+
local writeFns = table.create(dataCount) :: { any }
|
|
145
|
+
local readFns = table.create(dataCount) :: { any }
|
|
146
146
|
for i = 1, dataCount do
|
|
147
147
|
writeFns[i] = dataCodecs[i].write
|
|
148
148
|
readFns[i] = dataCodecs[i].read
|
|
149
149
|
end
|
|
150
|
-
table.freeze
|
|
151
|
-
table.freeze
|
|
150
|
+
table.freeze(writeFns)
|
|
151
|
+
table.freeze(readFns)
|
|
152
152
|
|
|
153
|
-
return table.freeze
|
|
153
|
+
return table.freeze({
|
|
154
154
|
_size = if isAllFixed then fixedSize else nil,
|
|
155
155
|
|
|
156
|
-
write = function
|
|
156
|
+
write = function(ch: ChannelState, value: any): ()
|
|
157
157
|
if isAllFixed then
|
|
158
|
-
alloc
|
|
158
|
+
alloc(ch, fixedSize)
|
|
159
159
|
end
|
|
160
160
|
|
|
161
161
|
for i = 1, dataCount do
|
|
162
|
-
writeFns[i]
|
|
162
|
+
writeFns[i](ch, value[dataKeys[i]])
|
|
163
163
|
end
|
|
164
164
|
|
|
165
165
|
if hasBools then
|
|
166
|
-
packBools
|
|
166
|
+
packBools(ch, boolKeys, boolCount, value)
|
|
167
167
|
end
|
|
168
168
|
end,
|
|
169
|
-
read = function
|
|
169
|
+
read = function(src: buffer, pos: number, refs: { Instance }?): (any, number)
|
|
170
170
|
local result = {}
|
|
171
171
|
local absPos = pos
|
|
172
172
|
|
|
173
173
|
for i = 1, dataCount do
|
|
174
|
-
local value, n = readFns[i]
|
|
174
|
+
local value, n = readFns[i](src, absPos, refs)
|
|
175
175
|
result[dataKeys[i]] = value
|
|
176
176
|
absPos += n
|
|
177
177
|
end
|
|
178
178
|
|
|
179
179
|
if hasBools then
|
|
180
|
-
absPos += unpackBools
|
|
180
|
+
absPos += unpackBools(src, absPos, boolKeys, boolCount, result)
|
|
181
181
|
end
|
|
182
182
|
|
|
183
183
|
return result, absPos - pos
|
|
@@ -185,33 +185,33 @@ function Struct.struct (schema: { [string]: Codec<any> }): Codec<any>
|
|
|
185
185
|
})
|
|
186
186
|
end
|
|
187
187
|
|
|
188
|
-
function Struct.deltaStruct
|
|
189
|
-
local dataKeys, dataCodecs, boolKeys = extractFields
|
|
188
|
+
function Struct.deltaStruct(schema: { [string]: Codec<any> }): Codec<any>
|
|
189
|
+
local dataKeys, dataCodecs, boolKeys = extractFields(schema)
|
|
190
190
|
|
|
191
191
|
local dataCount = #dataKeys
|
|
192
192
|
local boolCount = #boolKeys
|
|
193
|
-
local boolByteCount = ceil
|
|
193
|
+
local boolByteCount = ceil(boolCount / 8)
|
|
194
194
|
local segCount = dataCount + (if boolCount > 0 then 1 else 0)
|
|
195
|
-
local bitmaskBytes = ceil
|
|
196
|
-
local deltaId = Shared.allocDeltaId
|
|
195
|
+
local bitmaskBytes = ceil(segCount / 8)
|
|
196
|
+
local deltaId = Shared.allocDeltaId()
|
|
197
197
|
|
|
198
|
-
-- Scratch bounds reused every frame
|
|
199
|
-
local _scratchBounds = table.create
|
|
198
|
+
-- Scratch bounds reused every frame(only cloned into cache)
|
|
199
|
+
local _scratchBounds = table.create(segCount + 1) :: { number }
|
|
200
200
|
_scratchBounds[1] = 0
|
|
201
201
|
|
|
202
|
-
local writeFns = table.create
|
|
203
|
-
local readFns = table.create
|
|
202
|
+
local writeFns = table.create(dataCount) :: { any }
|
|
203
|
+
local readFns = table.create(dataCount) :: { any }
|
|
204
204
|
for i = 1, dataCount do
|
|
205
205
|
writeFns[i] = dataCodecs[i].write
|
|
206
206
|
readFns[i] = dataCodecs[i].read
|
|
207
207
|
end
|
|
208
|
-
table.freeze
|
|
209
|
-
table.freeze
|
|
208
|
+
table.freeze(writeFns)
|
|
209
|
+
table.freeze(readFns)
|
|
210
210
|
|
|
211
211
|
local scratchDirect = true
|
|
212
|
-
local scratchDirectWrites = table.create
|
|
213
|
-
local scratchFieldSizes = table.create
|
|
214
|
-
local scratchFieldOffsets = table.create
|
|
212
|
+
local scratchDirectWrites = table.create(dataCount) :: { any }
|
|
213
|
+
local scratchFieldSizes = table.create(dataCount) :: { number }
|
|
214
|
+
local scratchFieldOffsets = table.create(dataCount) :: { number }
|
|
215
215
|
local scratchDataTotal = 0
|
|
216
216
|
|
|
217
217
|
for i = 1, dataCount do
|
|
@@ -235,40 +235,40 @@ function Struct.deltaStruct (schema: { [string]: Codec<any> }): Codec<any>
|
|
|
235
235
|
-- 1024-byte scratch buffer.
|
|
236
236
|
local scratchSkipAlloc = scratchDirect and scratchTotalFixed <= 1024
|
|
237
237
|
|
|
238
|
-
return table.freeze
|
|
238
|
+
return table.freeze({
|
|
239
239
|
_isDelta = true,
|
|
240
240
|
|
|
241
|
-
write = function
|
|
241
|
+
write = function(ch: ChannelState, value: any): ()
|
|
242
242
|
local cache = ch.deltas[deltaId] :: DeltaCache?
|
|
243
|
-
local scratch = acquireScratch
|
|
243
|
+
local scratch = acquireScratch()
|
|
244
244
|
|
|
245
245
|
local bounds = _scratchBounds
|
|
246
246
|
bounds[1] = 0
|
|
247
247
|
|
|
248
248
|
if scratchDirect then
|
|
249
249
|
if not scratchSkipAlloc then
|
|
250
|
-
alloc
|
|
250
|
+
alloc(scratch, scratchTotalFixed)
|
|
251
251
|
end
|
|
252
252
|
local b = scratch.buff
|
|
253
253
|
|
|
254
254
|
for i = 1, dataCount do
|
|
255
|
-
scratchDirectWrites[i]
|
|
255
|
+
scratchDirectWrites[i](b, scratchFieldOffsets[i], value[dataKeys[i]])
|
|
256
256
|
bounds[i + 1] = scratchFieldOffsets[i] + scratchFieldSizes[i]
|
|
257
257
|
end
|
|
258
258
|
scratch.cursor = scratchDataTotal
|
|
259
259
|
|
|
260
260
|
if boolCount > 0 then
|
|
261
|
-
packBools
|
|
261
|
+
packBools(scratch, boolKeys, boolCount, value)
|
|
262
262
|
bounds[segCount + 1] = scratch.cursor
|
|
263
263
|
end
|
|
264
264
|
else
|
|
265
265
|
for i = 1, dataCount do
|
|
266
|
-
writeFns[i]
|
|
266
|
+
writeFns[i](scratch, value[dataKeys[i]])
|
|
267
267
|
bounds[i + 1] = scratch.cursor
|
|
268
268
|
end
|
|
269
269
|
|
|
270
270
|
if boolCount > 0 then
|
|
271
|
-
packBools
|
|
271
|
+
packBools(scratch, boolKeys, boolCount, value)
|
|
272
272
|
bounds[segCount + 1] = scratch.cursor
|
|
273
273
|
end
|
|
274
274
|
end
|
|
@@ -277,21 +277,21 @@ function Struct.deltaStruct (schema: { [string]: Codec<any> }): Codec<any>
|
|
|
277
277
|
|
|
278
278
|
-- FLAG_FULL: first frame, no cache exists yet
|
|
279
279
|
if not cache then
|
|
280
|
-
alloc
|
|
281
|
-
buffer.writeu8
|
|
280
|
+
alloc(ch, 1 + scratchTotal)
|
|
281
|
+
buffer.writeu8(ch.buff, ch.cursor, FLAG_FULL)
|
|
282
282
|
ch.cursor += 1
|
|
283
|
-
buffer.copy
|
|
283
|
+
buffer.copy(ch.buff, ch.cursor, scratch.buff, 0, scratchTotal)
|
|
284
284
|
ch.cursor += scratchTotal
|
|
285
285
|
|
|
286
286
|
-- FLAG_UNCHANGED: entire buffer is byte-identical to cache
|
|
287
287
|
elseif
|
|
288
288
|
scratchTotal == cache.total
|
|
289
|
-
and rangeEqual
|
|
289
|
+
and rangeEqual(scratch.buff, 0, cache.raw, 0, scratchTotal)
|
|
290
290
|
then
|
|
291
|
-
alloc
|
|
292
|
-
buffer.writeu8
|
|
291
|
+
alloc(ch, 1)
|
|
292
|
+
buffer.writeu8(ch.buff, ch.cursor, FLAG_UNCHANGED)
|
|
293
293
|
ch.cursor += 1
|
|
294
|
-
releaseScratch
|
|
294
|
+
releaseScratch()
|
|
295
295
|
return
|
|
296
296
|
|
|
297
297
|
-- FLAG_DELTA: per-segment dirty mask + dirty payloads
|
|
@@ -308,28 +308,28 @@ function Struct.deltaStruct (schema: { [string]: Codec<any> }): Codec<any>
|
|
|
308
308
|
|
|
309
309
|
if
|
|
310
310
|
newLen ~= oldLen
|
|
311
|
-
or not rangeEqual
|
|
311
|
+
or not rangeEqual(scratch.buff, newOff, cacheRaw, oldOff, newLen)
|
|
312
312
|
then
|
|
313
|
-
mask = bor
|
|
313
|
+
mask = bor(mask, lshift(1, i - 1))
|
|
314
314
|
end
|
|
315
315
|
end
|
|
316
316
|
|
|
317
|
-
alloc
|
|
318
|
-
buffer.writeu8
|
|
319
|
-
buffer.writeu8
|
|
317
|
+
alloc(ch, 2)
|
|
318
|
+
buffer.writeu8(ch.buff, ch.cursor, FLAG_DELTA)
|
|
319
|
+
buffer.writeu8(ch.buff, ch.cursor + 1, mask)
|
|
320
320
|
ch.cursor += 2
|
|
321
321
|
|
|
322
322
|
for i = 1, segCount do
|
|
323
|
-
if band
|
|
323
|
+
if band(mask, lshift(1, i - 1)) ~= 0 then
|
|
324
324
|
local newOff = bounds[i]
|
|
325
325
|
local newLen = bounds[i + 1] - newOff
|
|
326
|
-
alloc
|
|
327
|
-
buffer.copy
|
|
326
|
+
alloc(ch, newLen)
|
|
327
|
+
buffer.copy(ch.buff, ch.cursor, scratch.buff, newOff, newLen)
|
|
328
328
|
ch.cursor += newLen
|
|
329
329
|
end
|
|
330
330
|
end
|
|
331
331
|
else
|
|
332
|
-
local maskBuf = table.create
|
|
332
|
+
local maskBuf = table.create(bitmaskBytes, 0)
|
|
333
333
|
local cacheRaw = cache.raw
|
|
334
334
|
local cacheBds = cache.bounds
|
|
335
335
|
|
|
@@ -341,102 +341,102 @@ function Struct.deltaStruct (schema: { [string]: Codec<any> }): Codec<any>
|
|
|
341
341
|
|
|
342
342
|
if
|
|
343
343
|
newLen ~= oldLen
|
|
344
|
-
or not rangeEqual
|
|
344
|
+
or not rangeEqual(scratch.buff, newOff, cacheRaw, oldOff, newLen)
|
|
345
345
|
then
|
|
346
346
|
local bitIdx = i - 1
|
|
347
347
|
local byteIdx = bitIdx // 8 + 1
|
|
348
|
-
maskBuf[byteIdx] = bor
|
|
348
|
+
maskBuf[byteIdx] = bor(maskBuf[byteIdx], lshift(1, bitIdx % 8))
|
|
349
349
|
end
|
|
350
350
|
end
|
|
351
351
|
|
|
352
|
-
alloc
|
|
353
|
-
buffer.writeu8
|
|
352
|
+
alloc(ch, 1 + bitmaskBytes)
|
|
353
|
+
buffer.writeu8(ch.buff, ch.cursor, FLAG_DELTA)
|
|
354
354
|
ch.cursor += 1
|
|
355
355
|
|
|
356
356
|
local maskStart = ch.cursor
|
|
357
357
|
for byteIdx = 1, bitmaskBytes do
|
|
358
|
-
buffer.writeu8
|
|
358
|
+
buffer.writeu8(ch.buff, maskStart + byteIdx - 1, maskBuf[byteIdx])
|
|
359
359
|
end
|
|
360
360
|
ch.cursor = maskStart + bitmaskBytes
|
|
361
361
|
|
|
362
362
|
for i = 1, segCount do
|
|
363
363
|
local bitIdx = i - 1
|
|
364
364
|
local byteIdx = bitIdx // 8 + 1
|
|
365
|
-
if band
|
|
365
|
+
if band(maskBuf[byteIdx], lshift(1, bitIdx % 8)) ~= 0 then
|
|
366
366
|
local newOff = bounds[i]
|
|
367
367
|
local newLen = bounds[i + 1] - newOff
|
|
368
|
-
alloc
|
|
369
|
-
buffer.copy
|
|
368
|
+
alloc(ch, newLen)
|
|
369
|
+
buffer.copy(ch.buff, ch.cursor, scratch.buff, newOff, newLen)
|
|
370
370
|
ch.cursor += newLen
|
|
371
371
|
end
|
|
372
372
|
end
|
|
373
373
|
end
|
|
374
374
|
|
|
375
|
-
local rawBuf = buffer.create
|
|
376
|
-
buffer.copy
|
|
375
|
+
local rawBuf = buffer.create(scratchTotal)
|
|
376
|
+
buffer.copy(rawBuf, 0, scratch.buff, 0, scratchTotal)
|
|
377
377
|
|
|
378
|
-
local cacheBounds = table.clone
|
|
379
|
-
table.freeze
|
|
378
|
+
local cacheBounds = table.clone(bounds)
|
|
379
|
+
table.freeze(cacheBounds)
|
|
380
380
|
ch.deltas[deltaId] = {
|
|
381
381
|
raw = rawBuf,
|
|
382
382
|
bounds = cacheBounds,
|
|
383
383
|
total = scratchTotal,
|
|
384
384
|
} :: DeltaCache
|
|
385
385
|
|
|
386
|
-
releaseScratch
|
|
386
|
+
releaseScratch()
|
|
387
387
|
end,
|
|
388
388
|
|
|
389
|
-
read = function
|
|
390
|
-
local flag = buffer.readu8
|
|
389
|
+
read = function(src: buffer, pos: number, refs: { Instance }?): (any, number)
|
|
390
|
+
local flag = buffer.readu8(src, pos)
|
|
391
391
|
local absPos = pos + 1
|
|
392
392
|
|
|
393
393
|
if flag == FLAG_UNCHANGED then
|
|
394
|
-
local cache = Baseline.getCache
|
|
395
|
-
return if cache then table.clone
|
|
394
|
+
local cache = Baseline.getCache(deltaId) :: any
|
|
395
|
+
return if cache then table.clone(cache) else {}, 1
|
|
396
396
|
end
|
|
397
397
|
|
|
398
398
|
if flag == FLAG_FULL then
|
|
399
399
|
local result = {}
|
|
400
400
|
|
|
401
401
|
for i = 1, dataCount do
|
|
402
|
-
local val, n = readFns[i]
|
|
402
|
+
local val, n = readFns[i](src, absPos, refs)
|
|
403
403
|
result[dataKeys[i]] = val
|
|
404
404
|
absPos += n
|
|
405
405
|
end
|
|
406
406
|
|
|
407
407
|
if boolCount > 0 then
|
|
408
|
-
absPos += unpackBools
|
|
408
|
+
absPos += unpackBools(src, absPos, boolKeys, boolCount, result)
|
|
409
409
|
end
|
|
410
410
|
|
|
411
|
-
Baseline.setCache
|
|
411
|
+
Baseline.setCache(deltaId, result)
|
|
412
412
|
return result, absPos - pos
|
|
413
413
|
end
|
|
414
414
|
|
|
415
|
-
local cache = Baseline.getCache
|
|
416
|
-
local result = if cache then table.clone
|
|
415
|
+
local cache = Baseline.getCache(deltaId) :: any
|
|
416
|
+
local result = if cache then table.clone(cache) else {}
|
|
417
417
|
|
|
418
418
|
local maskStart = absPos
|
|
419
419
|
absPos += bitmaskBytes
|
|
420
420
|
|
|
421
421
|
for i = 1, segCount do
|
|
422
422
|
local bitIdx = i - 1
|
|
423
|
-
local byte = buffer.readu8
|
|
423
|
+
local byte = buffer.readu8(src, maskStart + (bitIdx // 8))
|
|
424
424
|
|
|
425
|
-
if band
|
|
425
|
+
if band(byte, lshift(1, bitIdx % 8)) ~= 0 then
|
|
426
426
|
if i <= dataCount then
|
|
427
|
-
local val, n = readFns[i]
|
|
427
|
+
local val, n = readFns[i](src, absPos, refs)
|
|
428
428
|
result[dataKeys[i]] = val
|
|
429
429
|
absPos += n
|
|
430
430
|
else
|
|
431
|
-
absPos += unpackBools
|
|
431
|
+
absPos += unpackBools(src, absPos, boolKeys, boolCount, result)
|
|
432
432
|
end
|
|
433
433
|
end
|
|
434
434
|
end
|
|
435
435
|
|
|
436
|
-
Baseline.setCache
|
|
436
|
+
Baseline.setCache(deltaId, result)
|
|
437
437
|
return result, absPos - pos
|
|
438
438
|
end,
|
|
439
439
|
})
|
|
440
440
|
end
|
|
441
441
|
|
|
442
|
-
return table.freeze
|
|
442
|
+
return table.freeze(Struct)
|