@axpecter/lync 1.3.1 → 1.4.1
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 +250 -68
- package/package.json +1 -1
- package/src/Types.luau +13 -2
- package/src/api/Group.luau +77 -46
- package/src/api/Namespace.luau +13 -6
- package/src/api/Packet.luau +52 -30
- package/src/api/Query.luau +116 -90
- package/src/api/Scope.luau +73 -0
- package/src/api/Signal.luau +10 -4
- package/src/codec/Base.luau +7 -3
- package/src/codec/composite/Array.luau +18 -15
- package/src/codec/composite/Map.luau +45 -31
- package/src/codec/composite/Optional.luau +3 -2
- package/src/codec/composite/Shared.luau +7 -5
- package/src/codec/composite/Struct.luau +6 -4
- package/src/codec/composite/Tagged.luau +6 -6
- package/src/codec/composite/Tuple.luau +9 -7
- package/src/codec/datatype/Buffer.luau +3 -2
- package/src/codec/datatype/CFrame.luau +2 -1
- package/src/codec/datatype/Instance.luau +3 -2
- package/src/codec/datatype/Sequence.luau +3 -4
- package/src/codec/datatype/String.luau +3 -6
- package/src/codec/meta/Auto.luau +77 -72
- package/src/codec/meta/Bitfield.luau +5 -4
- package/src/codec/meta/Enum.luau +6 -5
- package/src/codec/meta/Quantized.luau +5 -4
- package/src/codec/meta/Unknown.luau +5 -1
- package/src/codec/primitive/Float16.luau +5 -4
- package/src/codec/primitive/Varint.luau +2 -2
- package/src/index.d.ts +65 -26
- package/src/init.luau +60 -42
- package/src/internal/Baseline.luau +6 -2
- package/src/internal/Channel.luau +11 -6
- package/src/internal/Middleware.luau +18 -8
- package/src/internal/Pool.luau +5 -5
- package/src/internal/Registry.luau +4 -4
- package/src/transport/Bridge.luau +4 -3
- package/src/transport/Client.luau +4 -3
- package/src/transport/Gate.luau +5 -5
- package/src/transport/Reader.luau +3 -3
- package/src/transport/Server.luau +14 -16
package/src/codec/meta/Auto.luau
CHANGED
|
@@ -2,29 +2,32 @@
|
|
|
2
2
|
--!native
|
|
3
3
|
-- Auto (self-describing) codec. Writes a u8 type tag then the value.
|
|
4
4
|
|
|
5
|
-
local
|
|
5
|
+
local BoolCodec = require (script.Parent.Parent.primitive.Bool)
|
|
6
|
+
local BufferCodec = require (script.Parent.Parent.datatype.Buffer)
|
|
6
7
|
local CFrameCodec = require (script.Parent.Parent.datatype.CFrame)
|
|
7
8
|
local Channel = require (script.Parent.Parent.Parent.internal.Channel)
|
|
8
|
-
local
|
|
9
|
-
local
|
|
10
|
-
local
|
|
11
|
-
local IntVector = require (script.Parent.Parent.datatype.IntVector)
|
|
12
|
-
local Number = require (script.Parent.Parent.primitive.Number)
|
|
9
|
+
local ColorCodec = require (script.Parent.Parent.datatype.Color)
|
|
10
|
+
local IntVectorCodec = require (script.Parent.Parent.datatype.IntVector)
|
|
11
|
+
local NumberCodec = require (script.Parent.Parent.primitive.Number)
|
|
13
12
|
local NumberRangeCodec = require (script.Parent.Parent.datatype.NumberRange)
|
|
14
13
|
local RayCodec = require (script.Parent.Parent.datatype.Ray)
|
|
15
14
|
local RectCodec = require (script.Parent.Parent.datatype.Rect)
|
|
16
|
-
local
|
|
17
|
-
local
|
|
18
|
-
local
|
|
15
|
+
local RegionCodec = require (script.Parent.Parent.datatype.Region)
|
|
16
|
+
local SequenceCodec = require (script.Parent.Parent.datatype.Sequence)
|
|
17
|
+
local StringCodec = require (script.Parent.Parent.datatype.String)
|
|
19
18
|
local Types = require (script.Parent.Parent.Parent.Types)
|
|
20
19
|
local UDimCodec = require (script.Parent.Parent.datatype.UDim)
|
|
21
20
|
local Varint = require (script.Parent.Parent.primitive.Varint)
|
|
22
|
-
local
|
|
21
|
+
local VectorCodec = require (script.Parent.Parent.datatype.Vector)
|
|
23
22
|
|
|
24
23
|
type ChannelState = Types.ChannelState
|
|
25
24
|
type Codec<T> = Types.Codec<T>
|
|
25
|
+
type InternalCodec<T> = Types.InternalCodec<T>
|
|
26
|
+
|
|
27
|
+
local alloc = Channel.alloc
|
|
28
|
+
local floor = math.floor
|
|
26
29
|
|
|
27
|
-
-- Constants
|
|
30
|
+
-- Constants ----------------------------------------------------------
|
|
28
31
|
|
|
29
32
|
local TAG_NIL = 0
|
|
30
33
|
local TAG_BOOL = 1
|
|
@@ -54,128 +57,130 @@ local TAG_RAY = 24
|
|
|
54
57
|
local TAG_NUMBERSEQUENCE = 25
|
|
55
58
|
local TAG_COLORSEQUENCE = 26
|
|
56
59
|
|
|
57
|
-
local floor = math.floor
|
|
58
|
-
|
|
59
60
|
local READ_DISPATCH = table.freeze ({
|
|
60
61
|
[TAG_BOOL] = BoolCodec.bool,
|
|
61
|
-
[TAG_U8] =
|
|
62
|
-
[TAG_U16] =
|
|
63
|
-
[TAG_U32] =
|
|
64
|
-
[TAG_I8] =
|
|
65
|
-
[TAG_I16] =
|
|
66
|
-
[TAG_I32] =
|
|
67
|
-
[TAG_F32] =
|
|
68
|
-
[TAG_F64] =
|
|
69
|
-
[TAG_STRING] =
|
|
70
|
-
[TAG_VEC2] =
|
|
71
|
-
[TAG_VEC3] =
|
|
72
|
-
[TAG_COLOR3] =
|
|
62
|
+
[TAG_U8] = NumberCodec.u8,
|
|
63
|
+
[TAG_U16] = NumberCodec.u16,
|
|
64
|
+
[TAG_U32] = NumberCodec.u32,
|
|
65
|
+
[TAG_I8] = NumberCodec.i8,
|
|
66
|
+
[TAG_I16] = NumberCodec.i16,
|
|
67
|
+
[TAG_I32] = NumberCodec.i32,
|
|
68
|
+
[TAG_F32] = NumberCodec.f32,
|
|
69
|
+
[TAG_F64] = NumberCodec.f64,
|
|
70
|
+
[TAG_STRING] = StringCodec.string,
|
|
71
|
+
[TAG_VEC2] = VectorCodec.vec2,
|
|
72
|
+
[TAG_VEC3] = VectorCodec.vec3,
|
|
73
|
+
[TAG_COLOR3] = ColorCodec.color3,
|
|
73
74
|
[TAG_CFRAME] = CFrameCodec.cframe,
|
|
74
|
-
[TAG_BUFFER] =
|
|
75
|
+
[TAG_BUFFER] = BufferCodec.buff,
|
|
75
76
|
[TAG_UDIM] = UDimCodec.udim,
|
|
76
77
|
[TAG_UDIM2] = UDimCodec.udim2,
|
|
77
78
|
[TAG_NUMBERRANGE] = NumberRangeCodec.numberRange,
|
|
78
79
|
[TAG_RECT] = RectCodec.rect,
|
|
79
|
-
[TAG_VEC2INT16] =
|
|
80
|
-
[TAG_VEC3INT16] =
|
|
81
|
-
[TAG_REGION3] =
|
|
82
|
-
[TAG_REGION3INT16] =
|
|
80
|
+
[TAG_VEC2INT16] = IntVectorCodec.vec2int16,
|
|
81
|
+
[TAG_VEC3INT16] = IntVectorCodec.vec3int16,
|
|
82
|
+
[TAG_REGION3] = RegionCodec.region3,
|
|
83
|
+
[TAG_REGION3INT16] = RegionCodec.region3int16,
|
|
83
84
|
[TAG_RAY] = RayCodec.ray,
|
|
84
|
-
[TAG_NUMBERSEQUENCE] =
|
|
85
|
-
[TAG_COLORSEQUENCE] =
|
|
85
|
+
[TAG_NUMBERSEQUENCE] = SequenceCodec.numberSequence,
|
|
86
|
+
[TAG_COLORSEQUENCE] = SequenceCodec.colorSequence,
|
|
86
87
|
})
|
|
87
88
|
|
|
89
|
+
local function extractDw (codec: any): any
|
|
90
|
+
return (codec :: InternalCodec<any>)._directWrite
|
|
91
|
+
end
|
|
92
|
+
|
|
88
93
|
local TYPE_DISPATCH = table.freeze ({
|
|
89
94
|
boolean = { tag = TAG_BOOL, codec = BoolCodec.bool, size = 1, dw = nil },
|
|
90
|
-
string = { tag = TAG_STRING, codec =
|
|
95
|
+
string = { tag = TAG_STRING, codec = StringCodec.string, size = nil, dw = nil },
|
|
96
|
+
buffer = { tag = TAG_BUFFER, codec = BufferCodec.buff, size = nil, dw = nil },
|
|
91
97
|
Vector2 = {
|
|
92
98
|
tag = TAG_VEC2,
|
|
93
|
-
codec =
|
|
99
|
+
codec = VectorCodec.vec2,
|
|
94
100
|
size = 8,
|
|
95
|
-
dw = (
|
|
101
|
+
dw = extractDw (VectorCodec.vec2),
|
|
96
102
|
},
|
|
97
103
|
Vector3 = {
|
|
98
104
|
tag = TAG_VEC3,
|
|
99
|
-
codec =
|
|
105
|
+
codec = VectorCodec.vec3,
|
|
100
106
|
size = 12,
|
|
101
|
-
dw = (
|
|
107
|
+
dw = extractDw (VectorCodec.vec3),
|
|
102
108
|
},
|
|
103
109
|
Color3 = {
|
|
104
110
|
tag = TAG_COLOR3,
|
|
105
|
-
codec =
|
|
111
|
+
codec = ColorCodec.color3,
|
|
106
112
|
size = 3,
|
|
107
|
-
dw = (
|
|
113
|
+
dw = extractDw (ColorCodec.color3),
|
|
108
114
|
},
|
|
109
115
|
CFrame = {
|
|
110
116
|
tag = TAG_CFRAME,
|
|
111
117
|
codec = CFrameCodec.cframe,
|
|
112
118
|
size = 24,
|
|
113
|
-
dw = (CFrameCodec.cframe
|
|
119
|
+
dw = extractDw (CFrameCodec.cframe),
|
|
114
120
|
},
|
|
115
|
-
buffer = { tag = TAG_BUFFER, codec = Buffer.buff, size = nil, dw = nil },
|
|
116
121
|
UDim = {
|
|
117
122
|
tag = TAG_UDIM,
|
|
118
123
|
codec = UDimCodec.udim,
|
|
119
124
|
size = 8,
|
|
120
|
-
dw = (UDimCodec.udim
|
|
125
|
+
dw = extractDw (UDimCodec.udim),
|
|
121
126
|
},
|
|
122
127
|
UDim2 = {
|
|
123
128
|
tag = TAG_UDIM2,
|
|
124
129
|
codec = UDimCodec.udim2,
|
|
125
130
|
size = 16,
|
|
126
|
-
dw = (UDimCodec.udim2
|
|
131
|
+
dw = extractDw (UDimCodec.udim2),
|
|
127
132
|
},
|
|
128
133
|
NumberRange = {
|
|
129
134
|
tag = TAG_NUMBERRANGE,
|
|
130
135
|
codec = NumberRangeCodec.numberRange,
|
|
131
136
|
size = 8,
|
|
132
|
-
dw = (NumberRangeCodec.numberRange
|
|
137
|
+
dw = extractDw (NumberRangeCodec.numberRange),
|
|
133
138
|
},
|
|
134
139
|
Rect = {
|
|
135
140
|
tag = TAG_RECT,
|
|
136
141
|
codec = RectCodec.rect,
|
|
137
142
|
size = 16,
|
|
138
|
-
dw = (RectCodec.rect
|
|
143
|
+
dw = extractDw (RectCodec.rect),
|
|
139
144
|
},
|
|
140
145
|
Vector2int16 = {
|
|
141
146
|
tag = TAG_VEC2INT16,
|
|
142
|
-
codec =
|
|
147
|
+
codec = IntVectorCodec.vec2int16,
|
|
143
148
|
size = 4,
|
|
144
|
-
dw = (
|
|
149
|
+
dw = extractDw (IntVectorCodec.vec2int16),
|
|
145
150
|
},
|
|
146
151
|
Vector3int16 = {
|
|
147
152
|
tag = TAG_VEC3INT16,
|
|
148
|
-
codec =
|
|
153
|
+
codec = IntVectorCodec.vec3int16,
|
|
149
154
|
size = 6,
|
|
150
|
-
dw = (
|
|
155
|
+
dw = extractDw (IntVectorCodec.vec3int16),
|
|
151
156
|
},
|
|
152
157
|
Region3 = {
|
|
153
158
|
tag = TAG_REGION3,
|
|
154
|
-
codec =
|
|
159
|
+
codec = RegionCodec.region3,
|
|
155
160
|
size = 24,
|
|
156
|
-
dw = (
|
|
161
|
+
dw = extractDw (RegionCodec.region3),
|
|
157
162
|
},
|
|
158
163
|
Region3int16 = {
|
|
159
164
|
tag = TAG_REGION3INT16,
|
|
160
|
-
codec =
|
|
165
|
+
codec = RegionCodec.region3int16,
|
|
161
166
|
size = 12,
|
|
162
|
-
dw = (
|
|
167
|
+
dw = extractDw (RegionCodec.region3int16),
|
|
163
168
|
},
|
|
164
169
|
Ray = {
|
|
165
170
|
tag = TAG_RAY,
|
|
166
171
|
codec = RayCodec.ray,
|
|
167
172
|
size = 24,
|
|
168
|
-
dw = (RayCodec.ray
|
|
173
|
+
dw = extractDw (RayCodec.ray),
|
|
169
174
|
},
|
|
170
175
|
NumberSequence = {
|
|
171
176
|
tag = TAG_NUMBERSEQUENCE,
|
|
172
|
-
codec =
|
|
177
|
+
codec = SequenceCodec.numberSequence,
|
|
173
178
|
size = nil,
|
|
174
179
|
dw = nil,
|
|
175
180
|
},
|
|
176
181
|
ColorSequence = {
|
|
177
182
|
tag = TAG_COLORSEQUENCE,
|
|
178
|
-
codec =
|
|
183
|
+
codec = SequenceCodec.colorSequence,
|
|
179
184
|
size = nil,
|
|
180
185
|
dw = nil,
|
|
181
186
|
},
|
|
@@ -187,24 +192,24 @@ local NUM_DWRITES = {} :: { [number]: any }
|
|
|
187
192
|
|
|
188
193
|
for _, pair in
|
|
189
194
|
{
|
|
190
|
-
{ TAG_U8,
|
|
191
|
-
{ TAG_U16,
|
|
192
|
-
{ TAG_U32,
|
|
193
|
-
{ TAG_I8,
|
|
194
|
-
{ TAG_I16,
|
|
195
|
-
{ TAG_I32,
|
|
196
|
-
{ TAG_F32,
|
|
197
|
-
{ TAG_F64,
|
|
195
|
+
{ TAG_U8, NumberCodec.u8, 1 },
|
|
196
|
+
{ TAG_U16, NumberCodec.u16, 2 },
|
|
197
|
+
{ TAG_U32, NumberCodec.u32, 4 },
|
|
198
|
+
{ TAG_I8, NumberCodec.i8, 1 },
|
|
199
|
+
{ TAG_I16, NumberCodec.i16, 2 },
|
|
200
|
+
{ TAG_I32, NumberCodec.i32, 4 },
|
|
201
|
+
{ TAG_F32, NumberCodec.f32, 4 },
|
|
202
|
+
{ TAG_F64, NumberCodec.f64, 8 },
|
|
198
203
|
}
|
|
199
204
|
do
|
|
200
205
|
NUM_SIZES[pair[1]] = pair[3]
|
|
201
|
-
NUM_DWRITES[pair[1]] = (pair[2] ::
|
|
206
|
+
NUM_DWRITES[pair[1]] = (pair[2] :: InternalCodec<number>)._directWrite
|
|
202
207
|
end
|
|
203
208
|
|
|
204
209
|
table.freeze (NUM_SIZES)
|
|
205
210
|
table.freeze (NUM_DWRITES)
|
|
206
211
|
|
|
207
|
-
-- Private
|
|
212
|
+
-- Private ------------------------------------------------------------
|
|
208
213
|
|
|
209
214
|
local _f32Temp = buffer.create (4)
|
|
210
215
|
|
|
@@ -246,7 +251,7 @@ local function selectNumberTag (value: number): number
|
|
|
246
251
|
return TAG_F64
|
|
247
252
|
end
|
|
248
253
|
|
|
249
|
-
-- Public
|
|
254
|
+
-- Public -------------------------------------------------------------
|
|
250
255
|
|
|
251
256
|
local auto = table.freeze ({
|
|
252
257
|
write = function (ch: ChannelState, value: any): ()
|
|
@@ -312,17 +317,17 @@ local auto = table.freeze ({
|
|
|
312
317
|
error (`[Lync] Auto unsupported type: {valueType}`)
|
|
313
318
|
end
|
|
314
319
|
|
|
315
|
-
local
|
|
316
|
-
local
|
|
317
|
-
if
|
|
318
|
-
local totalSize = 1 +
|
|
320
|
+
local entryDw = entry.dw
|
|
321
|
+
local entrySize = entry.size
|
|
322
|
+
if entryDw and entrySize then
|
|
323
|
+
local totalSize = 1 + entrySize
|
|
319
324
|
local c = ch.cursor
|
|
320
325
|
if c + totalSize > ch.size then
|
|
321
326
|
alloc (ch, totalSize)
|
|
322
327
|
end
|
|
323
328
|
local b = ch.buff
|
|
324
329
|
buffer.writeu8 (b, c, entry.tag)
|
|
325
|
-
|
|
330
|
+
entryDw (b, c + 1, value)
|
|
326
331
|
ch.cursor = c + totalSize
|
|
327
332
|
else
|
|
328
333
|
local c = ch.cursor
|
|
@@ -3,20 +3,21 @@
|
|
|
3
3
|
-- Pack booleans, unsigned and signed integers at the bit level.
|
|
4
4
|
|
|
5
5
|
local Channel = require (script.Parent.Parent.Parent.internal.Channel)
|
|
6
|
-
local alloc = Channel.alloc
|
|
7
6
|
local Types = require (script.Parent.Parent.Parent.Types)
|
|
8
7
|
|
|
9
8
|
type ChannelState = Types.ChannelState
|
|
10
9
|
type Codec<T> = Types.Codec<T>
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
local alloc = Channel.alloc
|
|
12
|
+
|
|
13
|
+
-- Constants ----------------------------------------------------------
|
|
13
14
|
|
|
14
15
|
local band = bit32.band
|
|
15
16
|
local bor = bit32.bor
|
|
16
17
|
local lshift = bit32.lshift
|
|
17
18
|
local rshift = bit32.rshift
|
|
18
19
|
|
|
19
|
-
-- Private
|
|
20
|
+
-- Private ------------------------------------------------------------
|
|
20
21
|
|
|
21
22
|
type FieldSpec = {
|
|
22
23
|
type: "bool" | "uint" | "int",
|
|
@@ -36,7 +37,7 @@ local function selectIO (bytes: number): ((b: buffer, offset: number, v: number)
|
|
|
36
37
|
return buffer.writeu32, buffer.readu32
|
|
37
38
|
end
|
|
38
39
|
|
|
39
|
-
-- Public
|
|
40
|
+
-- Public -------------------------------------------------------------
|
|
40
41
|
|
|
41
42
|
local Bitfield = {}
|
|
42
43
|
|
package/src/codec/meta/Enum.luau
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
-- String enum codec. Maps values to u8 indices at definition time.
|
|
4
4
|
|
|
5
5
|
local Channel = require (script.Parent.Parent.Parent.internal.Channel)
|
|
6
|
-
local alloc = Channel.alloc
|
|
7
6
|
local Types = require (script.Parent.Parent.Parent.Types)
|
|
8
7
|
|
|
9
8
|
type ChannelState = Types.ChannelState
|
|
10
9
|
type Codec<T> = Types.Codec<T>
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
local alloc = Channel.alloc
|
|
12
|
+
|
|
13
|
+
-- Public -------------------------------------------------------------
|
|
13
14
|
|
|
14
15
|
local EnumCodec = {}
|
|
15
16
|
|
|
@@ -28,7 +29,7 @@ function EnumCodec.define (...: string): Codec<string>
|
|
|
28
29
|
|
|
29
30
|
for i, value in values do
|
|
30
31
|
if toIndex[value] ~= nil then
|
|
31
|
-
error (`[Lync] Duplicate enum value:
|
|
32
|
+
error (`[Lync] Duplicate enum value: "{value}"`)
|
|
32
33
|
end
|
|
33
34
|
toIndex[value] = i - 1
|
|
34
35
|
toValue[i] = value
|
|
@@ -42,7 +43,7 @@ function EnumCodec.define (...: string): Codec<string>
|
|
|
42
43
|
_directWrite = function (b: buffer, offset: number, value: string): ()
|
|
43
44
|
local idx = toIndex[value]
|
|
44
45
|
if idx == nil then
|
|
45
|
-
error (`[Lync] Invalid enum value:
|
|
46
|
+
error (`[Lync] Invalid enum value: "{value}"`)
|
|
46
47
|
end
|
|
47
48
|
buffer.writeu8 (b, offset, idx)
|
|
48
49
|
end,
|
|
@@ -57,7 +58,7 @@ function EnumCodec.define (...: string): Codec<string>
|
|
|
57
58
|
write = function (ch: ChannelState, value: string): ()
|
|
58
59
|
local idx = toIndex[value]
|
|
59
60
|
if idx == nil then
|
|
60
|
-
error (`[Lync] Invalid enum value:
|
|
61
|
+
error (`[Lync] Invalid enum value: "{value}"`)
|
|
61
62
|
end
|
|
62
63
|
local c = ch.cursor
|
|
63
64
|
if c + 1 > ch.size then
|
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
-- Fixed-point compression. Maps float ranges to integer ranges.
|
|
4
4
|
|
|
5
5
|
local Channel = require (script.Parent.Parent.Parent.internal.Channel)
|
|
6
|
-
local alloc = Channel.alloc
|
|
7
6
|
local Types = require (script.Parent.Parent.Parent.Types)
|
|
8
7
|
|
|
9
8
|
type ChannelState = Types.ChannelState
|
|
10
9
|
type Codec<T> = Types.Codec<T>
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
local alloc = Channel.alloc
|
|
12
|
+
|
|
13
|
+
-- Constants ----------------------------------------------------------
|
|
13
14
|
|
|
14
15
|
local clamp = math.clamp
|
|
15
16
|
local round = math.round
|
|
@@ -19,7 +20,7 @@ local max = math.max
|
|
|
19
20
|
|
|
20
21
|
local U32_MAX = 4294967295
|
|
21
22
|
|
|
22
|
-
-- Private
|
|
23
|
+
-- Private ------------------------------------------------------------
|
|
23
24
|
|
|
24
25
|
local function selectIO (bytes: number): ((b: buffer, offset: number, v: number) -> (), (
|
|
25
26
|
b: buffer,
|
|
@@ -44,7 +45,7 @@ local function selectWidth (maxInt: number): number
|
|
|
44
45
|
return 4
|
|
45
46
|
end
|
|
46
47
|
|
|
47
|
-
-- Public
|
|
48
|
+
-- Public -------------------------------------------------------------
|
|
48
49
|
|
|
49
50
|
local Quantized = {}
|
|
50
51
|
|
|
@@ -3,11 +3,15 @@
|
|
|
3
3
|
-- Sidecar codec. Bypasses buffer serialization, uses Roblox remote refs.
|
|
4
4
|
|
|
5
5
|
local Channel = require (script.Parent.Parent.Parent.internal.Channel)
|
|
6
|
+
local Types = require (script.Parent.Parent.Parent.Types)
|
|
7
|
+
|
|
8
|
+
type ChannelState = Types.ChannelState
|
|
9
|
+
|
|
6
10
|
local alloc = Channel.alloc
|
|
7
11
|
|
|
8
12
|
return table.freeze ({
|
|
9
13
|
unknown = table.freeze ({
|
|
10
|
-
write = function (ch:
|
|
14
|
+
write = function (ch: ChannelState, value: any): ()
|
|
11
15
|
local refs = ch.refs
|
|
12
16
|
local idx = #refs + 1
|
|
13
17
|
if idx > 65535 then
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
-- Half-precision float codec. 2 bytes, ±65504, ~3 decimal digits.
|
|
4
4
|
|
|
5
5
|
local Channel = require (script.Parent.Parent.Parent.internal.Channel)
|
|
6
|
-
local alloc = Channel.alloc
|
|
7
6
|
local Types = require (script.Parent.Parent.Parent.Types)
|
|
8
7
|
|
|
8
|
+
local alloc = Channel.alloc
|
|
9
|
+
|
|
9
10
|
type ChannelState = Types.ChannelState
|
|
10
11
|
|
|
11
|
-
-- Constants
|
|
12
|
+
-- Constants ----------------------------------------------------------
|
|
12
13
|
|
|
13
14
|
local MAX_HALF = 65504
|
|
14
15
|
local BIAS = 15
|
|
@@ -28,7 +29,7 @@ local ldexp = math.ldexp
|
|
|
28
29
|
local round = math.round
|
|
29
30
|
local huge = math.huge
|
|
30
31
|
|
|
31
|
-
-- Private
|
|
32
|
+
-- Private ------------------------------------------------------------
|
|
32
33
|
|
|
33
34
|
local function encode (value: number): number
|
|
34
35
|
if value ~= value then
|
|
@@ -83,7 +84,7 @@ local function decode (packed: number): number
|
|
|
83
84
|
return if band (packed, SIGN_BIT) ~= 0 then -result else result
|
|
84
85
|
end
|
|
85
86
|
|
|
86
|
-
-- Public
|
|
87
|
+
-- Public -------------------------------------------------------------
|
|
87
88
|
|
|
88
89
|
local Float16 = {}
|
|
89
90
|
|
|
@@ -9,7 +9,7 @@ type ChannelState = Types.ChannelState
|
|
|
9
9
|
|
|
10
10
|
local alloc = Channel.alloc
|
|
11
11
|
|
|
12
|
-
-- Constants
|
|
12
|
+
-- Constants ----------------------------------------------------------
|
|
13
13
|
|
|
14
14
|
local CONT = 0x80
|
|
15
15
|
local MASK = 0x7F
|
|
@@ -21,7 +21,7 @@ local bor = bit32.bor
|
|
|
21
21
|
local rshift = bit32.rshift
|
|
22
22
|
local lshift = bit32.lshift
|
|
23
23
|
|
|
24
|
-
-- Public
|
|
24
|
+
-- Public -------------------------------------------------------------
|
|
25
25
|
|
|
26
26
|
local Varint = {}
|
|
27
27
|
|
package/src/index.d.ts
CHANGED
|
@@ -72,6 +72,46 @@ type InferBitfield<S extends Record<string, FieldSpec>> = Prettify<{
|
|
|
72
72
|
[K in keyof S]: InferFieldSpec<S[K]>;
|
|
73
73
|
}>;
|
|
74
74
|
|
|
75
|
+
// -- Target descriptors ------------------------------------------------
|
|
76
|
+
|
|
77
|
+
export interface AllTarget {
|
|
78
|
+
readonly _tag: "all";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface ExceptTarget {
|
|
82
|
+
readonly _tag: "except";
|
|
83
|
+
readonly _set: ReadonlyMap<Player, true>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface GroupObject {
|
|
87
|
+
readonly _tag: "group";
|
|
88
|
+
add(this: GroupObject, player: Player): boolean;
|
|
89
|
+
remove(this: GroupObject, player: Player): boolean;
|
|
90
|
+
has(this: GroupObject, player: Player): boolean;
|
|
91
|
+
count(this: GroupObject): number;
|
|
92
|
+
forEach(this: GroupObject, fn: (player: Player) => void): void;
|
|
93
|
+
getSet(this: GroupObject): ReadonlyMap<Player, true>;
|
|
94
|
+
destroy(this: GroupObject): void;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export type Target = Player | AllTarget | ExceptTarget | GroupObject | Player[];
|
|
98
|
+
|
|
99
|
+
// -- Scope -------------------------------------------------------------
|
|
100
|
+
|
|
101
|
+
export interface Scope {
|
|
102
|
+
add(this: Scope, conn: Connection | RBXScriptConnection): void;
|
|
103
|
+
listen<T>(this: Scope, source: Packet<T>, callback: (data: T, sender: Player | undefined) => void): void;
|
|
104
|
+
once<T>(this: Scope, source: Packet<T>, callback: (data: T, sender: Player | undefined) => void): void;
|
|
105
|
+
listenAll(this: Scope, namespace: Namespace, callback: (name: string, data: unknown, sender: Player | undefined) => void): void;
|
|
106
|
+
destroy(this: Scope): void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// -- DROP sentinel -----------------------------------------------------
|
|
110
|
+
|
|
111
|
+
export interface DropSentinel {
|
|
112
|
+
readonly _tag: "drop";
|
|
113
|
+
}
|
|
114
|
+
|
|
75
115
|
// -- Packet ------------------------------------------------------------
|
|
76
116
|
|
|
77
117
|
export interface PacketConfig<T> {
|
|
@@ -82,14 +122,8 @@ export interface PacketConfig<T> {
|
|
|
82
122
|
maxPayloadBytes?: number;
|
|
83
123
|
}
|
|
84
124
|
|
|
85
|
-
// Server methods throw on client and vice versa.
|
|
86
125
|
export interface Packet<T> {
|
|
87
|
-
|
|
88
|
-
sendToAll(this: Packet<T>, data: T): void;
|
|
89
|
-
sendToAllExcept(this: Packet<T>, data: T, except: Player): void;
|
|
90
|
-
sendToList(this: Packet<T>, data: T, players: Player[]): void;
|
|
91
|
-
sendToGroup(this: Packet<T>, data: T, groupName: string): void;
|
|
92
|
-
send(this: Packet<T>, data: T): void;
|
|
126
|
+
send(this: Packet<T>, data: T, target?: Target): void;
|
|
93
127
|
listen(this: Packet<T>, callback: (data: T, sender: Player | undefined) => void): Connection;
|
|
94
128
|
once(this: Packet<T>, callback: (data: T, sender: Player | undefined) => void): Connection;
|
|
95
129
|
wait(this: Packet<T>): LuaTuple<[T, Player | undefined]>;
|
|
@@ -111,17 +145,18 @@ export interface Query<Req, Resp> {
|
|
|
111
145
|
this: Query<Req, Resp>,
|
|
112
146
|
callback: (request: Req, player: Player) => Resp | undefined,
|
|
113
147
|
): Connection;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
148
|
+
request(this: Query<Req, Resp>, data: Req): Resp | undefined;
|
|
149
|
+
requestFrom(this: Query<Req, Resp>, player: Player, data: Req): Resp | undefined;
|
|
150
|
+
requestAll(this: Query<Req, Resp>, data: Req): Map<Player, Resp | undefined>;
|
|
151
|
+
requestList(
|
|
117
152
|
this: Query<Req, Resp>,
|
|
118
|
-
request: Req,
|
|
119
153
|
players: Player[],
|
|
154
|
+
data: Req,
|
|
120
155
|
): Map<Player, Resp | undefined>;
|
|
121
|
-
|
|
156
|
+
requestGroup(
|
|
122
157
|
this: Query<Req, Resp>,
|
|
123
|
-
|
|
124
|
-
|
|
158
|
+
group: GroupObject,
|
|
159
|
+
data: Req,
|
|
125
160
|
): Map<Player, Resp | undefined>;
|
|
126
161
|
}
|
|
127
162
|
|
|
@@ -143,6 +178,8 @@ type InferQueries<Q extends Record<string, QueryConfig<unknown, unknown>>> = {
|
|
|
143
178
|
};
|
|
144
179
|
|
|
145
180
|
export interface Namespace {
|
|
181
|
+
readonly packets: Record<string, Packet<unknown>>;
|
|
182
|
+
readonly queries: Record<string, Query<unknown, unknown>>;
|
|
146
183
|
listenAll(
|
|
147
184
|
this: Namespace,
|
|
148
185
|
callback: (name: string, data: unknown, sender: Player | undefined) => void,
|
|
@@ -166,7 +203,6 @@ export interface Namespace {
|
|
|
166
203
|
declare namespace Lync {
|
|
167
204
|
// Lifecycle
|
|
168
205
|
export const VERSION: string;
|
|
169
|
-
export const version: string;
|
|
170
206
|
export function start(): void;
|
|
171
207
|
|
|
172
208
|
// Definition
|
|
@@ -251,21 +287,24 @@ declare namespace Lync {
|
|
|
251
287
|
callback: (player: Player, reason: string, packetName: string, data: unknown) => void,
|
|
252
288
|
): () => void;
|
|
253
289
|
export function onSend(
|
|
254
|
-
handler: (data: unknown, name: string, player: Player | undefined) => unknown | undefined,
|
|
290
|
+
handler: (data: unknown, name: string, player: Player | undefined) => unknown | DropSentinel | undefined,
|
|
255
291
|
): () => void;
|
|
256
292
|
export function onReceive(
|
|
257
|
-
handler: (data: unknown, name: string, player: Player | undefined) => unknown | undefined,
|
|
293
|
+
handler: (data: unknown, name: string, player: Player | undefined) => unknown | DropSentinel | undefined,
|
|
258
294
|
): () => void;
|
|
259
295
|
|
|
296
|
+
// Target descriptors
|
|
297
|
+
export const all: AllTarget;
|
|
298
|
+
export function except(...players: Player[]): ExceptTarget;
|
|
299
|
+
|
|
300
|
+
// Middleware sentinel
|
|
301
|
+
export const DROP: DropSentinel;
|
|
302
|
+
|
|
260
303
|
// Groups
|
|
261
|
-
export function createGroup(name: string):
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
export function
|
|
265
|
-
export function hasInGroup(name: string, player: Player): boolean;
|
|
266
|
-
export function getGroupSet(name: string): ReadonlyMap<Player, true>;
|
|
267
|
-
export function groupCount(name: string): number;
|
|
268
|
-
export function forEachInGroup(name: string, fn: (player: Player) => void): void;
|
|
304
|
+
export function createGroup(name: string): GroupObject;
|
|
305
|
+
|
|
306
|
+
// Scope
|
|
307
|
+
export function scope(): Scope;
|
|
269
308
|
|
|
270
309
|
// Configuration
|
|
271
310
|
export function setChannelMaxSize(bytes: number): void;
|
|
@@ -276,4 +315,4 @@ declare namespace Lync {
|
|
|
276
315
|
export function queryPendingCount(): number;
|
|
277
316
|
}
|
|
278
317
|
|
|
279
|
-
export default Lync;
|
|
318
|
+
export default Lync;
|