@axpecter/lync 1.5.2 → 2.1.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 +499 -357
- package/package.json +2 -2
- package/src/Types.luau +69 -27
- package/src/api/Group.luau +101 -106
- package/src/api/Packet.luau +191 -157
- package/src/api/Query.luau +223 -282
- package/src/api/Scope.luau +46 -57
- package/src/api/Signal.luau +104 -137
- package/src/codec/Base.luau +69 -20
- package/src/codec/composite/Array.luau +189 -201
- package/src/codec/composite/Map.luau +97 -341
- package/src/codec/composite/Optional.luau +27 -23
- package/src/codec/composite/Shared.luau +96 -65
- package/src/codec/composite/Struct.luau +201 -339
- package/src/codec/composite/Tagged.luau +64 -178
- package/src/codec/composite/Tuple.luau +81 -95
- package/src/codec/datatype/Buffer.luau +49 -21
- package/src/codec/datatype/CFrame.luau +207 -30
- package/src/codec/datatype/Color.luau +21 -11
- package/src/codec/datatype/Instance.luau +29 -19
- package/src/codec/datatype/IntVector.luau +33 -21
- package/src/codec/datatype/NumberRange.luau +19 -10
- package/src/codec/datatype/Ray.luau +26 -22
- package/src/codec/datatype/Rect.luau +20 -16
- package/src/codec/datatype/Region.luau +51 -45
- package/src/codec/datatype/Sequence.luau +64 -56
- package/src/codec/datatype/String.luau +89 -56
- package/src/codec/datatype/UDim.luau +40 -22
- package/src/codec/datatype/Vector.luau +181 -17
- package/src/codec/meta/Auto.luau +295 -253
- package/src/codec/meta/Bitfield.luau +104 -148
- package/src/codec/meta/Custom.luau +8 -4
- package/src/codec/meta/Enum.luau +29 -57
- package/src/codec/meta/Float.luau +64 -0
- package/src/codec/meta/Nothing.luau +9 -5
- package/src/codec/meta/Unknown.luau +44 -35
- package/src/codec/primitive/Bool.luau +16 -26
- package/src/codec/primitive/Float16.luau +58 -64
- package/src/codec/primitive/Int.luau +68 -0
- package/src/codec/primitive/Number.luau +21 -43
- package/src/codec/primitive/Varint.luau +67 -46
- package/src/index.d.ts +249 -306
- package/src/init.luau +332 -173
- package/src/internal/Baseline.luau +29 -24
- package/src/internal/Channel.luau +346 -161
- package/src/internal/Middleware.luau +60 -85
- package/src/internal/Pool.luau +19 -30
- package/src/internal/Registry.luau +61 -101
- package/src/transport/Bridge.luau +64 -43
- package/src/transport/Client.luau +60 -117
- package/src/transport/Gate.luau +282 -133
- package/src/transport/Reader.luau +159 -100
- package/src/transport/Server.luau +147 -292
- package/src/api/Namespace.luau +0 -251
- package/src/codec/meta/Quantized.luau +0 -174
|
@@ -1,56 +1,74 @@
|
|
|
1
1
|
--!strict
|
|
2
2
|
--!native
|
|
3
|
-
-- Shared helpers for composite codecs: delta flags, scratch pool,
|
|
3
|
+
-- Shared helpers for composite codecs: delta flags, scratch pool, bool packing.
|
|
4
4
|
|
|
5
|
-
local
|
|
5
|
+
local Base = require(script.Parent.Parent.Base)
|
|
6
6
|
local Types = require(script.Parent.Parent.Parent.Types)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
-- Constants -----------------------------------------------------------
|
|
9
9
|
|
|
10
|
-
local
|
|
10
|
+
local DELTA_UNCHANGED = 0
|
|
11
|
+
local DELTA_FULL_OFFSET = 1
|
|
12
|
+
local DELTA_MULTI_OFFSET = 2
|
|
11
13
|
|
|
12
|
-
--
|
|
14
|
+
-- State ---------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
local _nextDeltaId = 0
|
|
17
|
+
local _scratchDepth = 0
|
|
18
|
+
local _scratchStack: { Types.ChannelState } = {}
|
|
19
|
+
|
|
20
|
+
-- Private -------------------------------------------------------------
|
|
13
21
|
|
|
22
|
+
local alloc = Base.alloc
|
|
14
23
|
local band = bit32.band
|
|
15
24
|
local bor = bit32.bor
|
|
25
|
+
local bxor = bit32.bxor
|
|
16
26
|
local lshift = bit32.lshift
|
|
17
|
-
local
|
|
18
|
-
local min = math.min
|
|
27
|
+
local rshift = bit32.rshift
|
|
19
28
|
|
|
20
|
-
local
|
|
21
|
-
local
|
|
22
|
-
local
|
|
23
|
-
|
|
24
|
-
-- State ---------------------------------------------------------------
|
|
25
|
-
|
|
26
|
-
local _nextDeltaId = 1
|
|
27
|
-
local _scratchStack = {} :: { ChannelState }
|
|
28
|
-
local _scratchDepth = 0
|
|
29
|
+
local readu8 = buffer.readu8
|
|
30
|
+
local readu32 = buffer.readu32
|
|
31
|
+
local writeu8 = buffer.writeu8
|
|
29
32
|
|
|
30
33
|
-- Public --------------------------------------------------------------
|
|
31
34
|
|
|
32
|
-
local Shared = {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
local Shared = {}
|
|
36
|
+
|
|
37
|
+
Shared.DELTA_UNCHANGED = DELTA_UNCHANGED
|
|
38
|
+
Shared.DELTA_FULL_OFFSET = DELTA_FULL_OFFSET
|
|
39
|
+
Shared.DELTA_MULTI_OFFSET = DELTA_MULTI_OFFSET
|
|
37
40
|
|
|
38
41
|
function Shared.allocDeltaId(): number
|
|
39
|
-
local id = _nextDeltaId
|
|
40
42
|
_nextDeltaId += 1
|
|
41
|
-
return
|
|
43
|
+
return _nextDeltaId
|
|
42
44
|
end
|
|
43
45
|
|
|
44
|
-
function Shared.acquireScratch(): ChannelState
|
|
46
|
+
function Shared.acquireScratch(): Types.ChannelState
|
|
45
47
|
_scratchDepth += 1
|
|
46
|
-
local
|
|
47
|
-
if not
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
local ch = _scratchStack[_scratchDepth]
|
|
49
|
+
if not ch then
|
|
50
|
+
ch = {
|
|
51
|
+
buff = buffer.create(1024),
|
|
52
|
+
cursor = 0,
|
|
53
|
+
size = 1024,
|
|
54
|
+
refs = {},
|
|
55
|
+
refCount = 0,
|
|
56
|
+
lastId = -1,
|
|
57
|
+
countPos = 0,
|
|
58
|
+
itemCount = 0,
|
|
59
|
+
singleMode = false,
|
|
60
|
+
singlePos = 0,
|
|
61
|
+
deltas = {},
|
|
62
|
+
prevDump = nil,
|
|
63
|
+
prevDumpLen = 0,
|
|
64
|
+
currentPacket = nil,
|
|
65
|
+
}
|
|
66
|
+
_scratchStack[_scratchDepth] = ch
|
|
67
|
+
else
|
|
68
|
+
ch.cursor = 0
|
|
69
|
+
ch.refCount = 0
|
|
50
70
|
end
|
|
51
|
-
|
|
52
|
-
table.clear(scratch.refs)
|
|
53
|
-
return scratch
|
|
71
|
+
return ch
|
|
54
72
|
end
|
|
55
73
|
|
|
56
74
|
function Shared.releaseScratch(): ()
|
|
@@ -58,42 +76,49 @@ function Shared.releaseScratch(): ()
|
|
|
58
76
|
end
|
|
59
77
|
|
|
60
78
|
function Shared.rangeEqual(a: buffer, offA: number, b: buffer, offB: number, len: number): boolean
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
79
|
+
-- u32 chunks
|
|
80
|
+
local aligned = len - (len % 4)
|
|
81
|
+
local i = 0
|
|
82
|
+
while i < aligned do
|
|
83
|
+
if bxor(readu32(a, offA + i), readu32(b, offB + i)) ~= 0 then
|
|
64
84
|
return false
|
|
65
85
|
end
|
|
86
|
+
i += 4
|
|
66
87
|
end
|
|
67
88
|
|
|
68
|
-
|
|
69
|
-
|
|
89
|
+
-- u8 remainder
|
|
90
|
+
while i < len do
|
|
91
|
+
if readu8(a, offA + i) ~= readu8(b, offB + i) then
|
|
70
92
|
return false
|
|
71
93
|
end
|
|
94
|
+
i += 1
|
|
72
95
|
end
|
|
73
96
|
|
|
74
97
|
return true
|
|
75
98
|
end
|
|
76
99
|
|
|
77
|
-
function Shared.extractFields(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
local
|
|
100
|
+
function Shared.extractFields(
|
|
101
|
+
schema: { [string]: Types.InternalCodec<any> }
|
|
102
|
+
): ({ string }, { Types.InternalCodec<any> }, { string })
|
|
103
|
+
local dataKeys: { string } = {}
|
|
104
|
+
local dataCodecs: { Types.InternalCodec<any> } = {}
|
|
105
|
+
local boolKeys: { string } = {}
|
|
81
106
|
|
|
82
107
|
for key, codec in schema do
|
|
83
|
-
if codec._isBool then
|
|
108
|
+
if (codec :: any)._isBool then
|
|
84
109
|
table.insert(boolKeys, key)
|
|
85
110
|
else
|
|
86
111
|
table.insert(dataKeys, key)
|
|
87
112
|
end
|
|
88
113
|
end
|
|
89
114
|
|
|
90
|
-
table.sort(dataKeys)
|
|
91
|
-
table.sort(boolKeys)
|
|
92
|
-
|
|
93
115
|
if #dataKeys == 0 and #boolKeys == 0 then
|
|
94
|
-
error("[Lync]
|
|
116
|
+
error("[Lync] Lync.struct: requires at least one field")
|
|
95
117
|
end
|
|
96
118
|
|
|
119
|
+
table.sort(dataKeys)
|
|
120
|
+
table.sort(boolKeys)
|
|
121
|
+
|
|
97
122
|
for i = 1, #dataKeys do
|
|
98
123
|
dataCodecs[i] = schema[dataKeys[i]]
|
|
99
124
|
end
|
|
@@ -105,27 +130,33 @@ function Shared.extractFields(schema: { [string]: any }): ({ string }, { any },
|
|
|
105
130
|
return dataKeys, dataCodecs, boolKeys
|
|
106
131
|
end
|
|
107
132
|
|
|
108
|
-
function Shared.packBools(
|
|
109
|
-
|
|
110
|
-
|
|
133
|
+
function Shared.packBools(
|
|
134
|
+
ch: Types.ChannelState,
|
|
135
|
+
value: any,
|
|
136
|
+
boolKeys: { string },
|
|
137
|
+
boolCount: number
|
|
138
|
+
): ()
|
|
139
|
+
local byteCount = (boolCount + 7) // 8
|
|
140
|
+
local cursor = ch.cursor
|
|
141
|
+
if cursor + byteCount > ch.size then
|
|
142
|
+
alloc(ch, byteCount)
|
|
143
|
+
end
|
|
111
144
|
local b = ch.buff
|
|
112
|
-
local c = ch.cursor
|
|
113
145
|
|
|
114
|
-
|
|
146
|
+
local idx = 1
|
|
147
|
+
for byteIdx = 0, byteCount - 1 do
|
|
115
148
|
local packed = 0
|
|
116
|
-
local
|
|
117
|
-
local limit = min(8, boolCount - base)
|
|
118
|
-
|
|
149
|
+
local limit = if idx + 8 <= boolCount + 1 then 8 else boolCount - idx + 1
|
|
119
150
|
for bit = 0, limit - 1 do
|
|
120
|
-
if value[boolKeys[
|
|
151
|
+
if value[boolKeys[idx]] then
|
|
121
152
|
packed = bor(packed, lshift(1, bit))
|
|
122
153
|
end
|
|
154
|
+
idx += 1
|
|
123
155
|
end
|
|
124
|
-
|
|
125
|
-
buffer.writeu8(b, c + byteIdx, packed)
|
|
156
|
+
writeu8(b, cursor + byteIdx, packed)
|
|
126
157
|
end
|
|
127
158
|
|
|
128
|
-
ch.cursor =
|
|
159
|
+
ch.cursor = cursor + byteCount
|
|
129
160
|
end
|
|
130
161
|
|
|
131
162
|
function Shared.unpackBools(
|
|
@@ -135,19 +166,19 @@ function Shared.unpackBools(
|
|
|
135
166
|
boolCount: number,
|
|
136
167
|
result: any
|
|
137
168
|
): number
|
|
138
|
-
local
|
|
139
|
-
|
|
140
|
-
for byteIdx = 0, boolByteCount - 1 do
|
|
141
|
-
local byte = buffer.readu8(src, pos + byteIdx)
|
|
142
|
-
local base = byteIdx * 8
|
|
143
|
-
local limit = min(8, boolCount - base)
|
|
169
|
+
local byteCount = (boolCount + 7) // 8
|
|
170
|
+
local idx = 1
|
|
144
171
|
|
|
172
|
+
for byteIdx = 0, byteCount - 1 do
|
|
173
|
+
local byte = readu8(src, pos + byteIdx)
|
|
174
|
+
local limit = if idx + 8 <= boolCount + 1 then 8 else boolCount - idx + 1
|
|
145
175
|
for bit = 0, limit - 1 do
|
|
146
|
-
result[boolKeys[
|
|
176
|
+
result[boolKeys[idx]] = band(byte, lshift(1, bit)) ~= 0
|
|
177
|
+
idx += 1
|
|
147
178
|
end
|
|
148
179
|
end
|
|
149
180
|
|
|
150
|
-
return
|
|
181
|
+
return byteCount
|
|
151
182
|
end
|
|
152
183
|
|
|
153
184
|
return table.freeze(Shared)
|