@axpecter/lync 2.1.2 → 2.2.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 +241 -349
- package/package.json +1 -1
- package/src/Types.luau +53 -13
- package/src/api/Group.luau +41 -51
- package/src/api/Packet.luau +145 -143
- package/src/api/Query.luau +204 -202
- package/src/api/Scope.luau +36 -38
- package/src/api/Signal.luau +68 -94
- package/src/codec/Base.luau +43 -23
- package/src/codec/composite/Array.luau +161 -152
- package/src/codec/composite/Map.luau +37 -53
- package/src/codec/composite/Optional.luau +15 -21
- package/src/codec/composite/Shared.luau +78 -41
- package/src/codec/composite/Struct.luau +64 -125
- package/src/codec/composite/Tagged.luau +15 -25
- package/src/codec/composite/Tuple.luau +15 -20
- package/src/codec/datatype/Buffer.luau +44 -51
- package/src/codec/datatype/CFrame.luau +72 -104
- package/src/codec/datatype/Color.luau +14 -10
- package/src/codec/datatype/Instance.luau +32 -42
- package/src/codec/datatype/IntVector.luau +24 -22
- package/src/codec/datatype/NumberRange.luau +21 -12
- package/src/codec/datatype/Ray.luau +13 -7
- package/src/codec/datatype/Rect.luau +13 -7
- package/src/codec/datatype/Region.luau +25 -22
- package/src/codec/datatype/Sequence.luau +144 -118
- package/src/codec/datatype/String.luau +29 -59
- package/src/codec/datatype/UDim.luau +29 -30
- package/src/codec/datatype/Vector.luau +89 -105
- package/src/codec/meta/Auto.luau +194 -246
- package/src/codec/meta/Bitfield.luau +37 -36
- package/src/codec/meta/Custom.luau +10 -10
- package/src/codec/meta/Enum.luau +8 -11
- package/src/codec/meta/Float.luau +16 -20
- package/src/codec/meta/Nothing.luau +2 -2
- package/src/codec/meta/Unknown.luau +22 -32
- package/src/codec/primitive/Bool.luau +9 -5
- package/src/codec/primitive/Float16.luau +13 -23
- package/src/codec/primitive/Int.luau +20 -28
- package/src/codec/primitive/Number.luau +6 -10
- package/src/codec/primitive/Signed.luau +32 -0
- package/src/codec/primitive/Varint.luau +59 -28
- package/src/index.d.ts +8 -2
- package/src/init.luau +118 -143
- package/src/internal/Baseline.luau +17 -18
- package/src/internal/Channel.luau +143 -212
- package/src/internal/Middleware.luau +37 -47
- package/src/internal/Pool.luau +10 -10
- package/src/internal/Registry.luau +38 -34
- package/src/internal/Transport.luau +28 -0
- package/src/internal/Util.luau +26 -0
- package/src/transport/Bridge.luau +32 -24
- package/src/transport/Client.luau +51 -53
- package/src/transport/Gate.luau +183 -113
- package/src/transport/Reader.luau +95 -66
- package/src/transport/Server.luau +130 -125
|
@@ -3,35 +3,37 @@
|
|
|
3
3
|
-- Vector2int16 (4 bytes) and Vector3int16 (6 bytes) codecs.
|
|
4
4
|
|
|
5
5
|
local Base = require(script.Parent.Parent.Base)
|
|
6
|
+
local Signed = require(script.Parent.Parent.primitive.Signed)
|
|
6
7
|
|
|
7
|
-
-- Private
|
|
8
|
+
-- Private ----------------------------------------------------------------
|
|
8
9
|
|
|
9
|
-
local
|
|
10
|
-
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
local function readI16(b: buffer, off: number): number
|
|
14
|
-
local raw = buffer.readu16(b, off)
|
|
15
|
-
return if raw >= 0x8000 then raw - 0x10000 else raw
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
-- Public --------------------------------------------------------------
|
|
10
|
+
local writeI16 = Signed.writeI16
|
|
11
|
+
local readi16 = buffer.readi16
|
|
19
12
|
|
|
20
|
-
local
|
|
21
|
-
|
|
22
|
-
IntVectorCodec.vec2int16 = Base.define(4, function(b: buffer, off: number, value: Vector2int16): ()
|
|
13
|
+
local function writeVec2I16(b: buffer, off: number, value: Vector2int16): ()
|
|
23
14
|
writeI16(b, off, value.X)
|
|
24
15
|
writeI16(b, off + 2, value.Y)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
local function readVec2I16(b: buffer, off: number): Vector2int16
|
|
19
|
+
return Vector2int16.new(readi16(b, off), readi16(b, off + 2))
|
|
20
|
+
end
|
|
28
21
|
|
|
29
|
-
|
|
22
|
+
local function writeVec3I16(b: buffer, off: number, value: Vector3int16): ()
|
|
30
23
|
writeI16(b, off, value.X)
|
|
31
24
|
writeI16(b, off + 2, value.Y)
|
|
32
25
|
writeI16(b, off + 4, value.Z)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
local function readVec3I16(b: buffer, off: number): Vector3int16
|
|
29
|
+
return Vector3int16.new(readi16(b, off), readi16(b, off + 2), readi16(b, off + 4))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
-- Public -----------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
local IntVector = {}
|
|
35
|
+
|
|
36
|
+
IntVector.vec2int16 = Base.define(4, writeVec2I16, readVec2I16, { _typeCheck = "Vector2int16" })
|
|
37
|
+
IntVector.vec3int16 = Base.define(6, writeVec3I16, readVec3I16, { _typeCheck = "Vector3int16" })
|
|
36
38
|
|
|
37
|
-
return table.freeze(
|
|
39
|
+
return table.freeze(IntVector)
|
|
@@ -4,20 +4,29 @@
|
|
|
4
4
|
|
|
5
5
|
local Base = require(script.Parent.Parent.Base)
|
|
6
6
|
|
|
7
|
-
--
|
|
7
|
+
-- Private ----------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
local function writeNumberRange(b: buffer, off: number, value: NumberRange): ()
|
|
10
|
+
buffer.writef32(b, off, value.Min)
|
|
11
|
+
buffer.writef32(b, off + 4, value.Max)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
local function readNumberRange(b: buffer, off: number): NumberRange
|
|
15
|
+
local minV = buffer.readf32(b, off)
|
|
16
|
+
local maxV = buffer.readf32(b, off + 4)
|
|
17
|
+
-- NumberRange.new requires min <= max; swap on corruption rather than throw.
|
|
18
|
+
if minV > maxV then
|
|
19
|
+
minV, maxV = maxV, minV
|
|
20
|
+
end
|
|
21
|
+
return NumberRange.new(minV, maxV)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
-- Public -----------------------------------------------------------------
|
|
8
25
|
|
|
9
26
|
local NumberRangeCodec = {}
|
|
10
27
|
|
|
11
|
-
NumberRangeCodec.numberRange = Base.define(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
buffer.writef32(b, off, value.Min)
|
|
15
|
-
buffer.writef32(b, off + 4, value.Max)
|
|
16
|
-
end,
|
|
17
|
-
function(b: buffer, off: number): NumberRange
|
|
18
|
-
return NumberRange.new(buffer.readf32(b, off), buffer.readf32(b, off + 4))
|
|
19
|
-
end,
|
|
20
|
-
{ _typeCheck = "NumberRange" }
|
|
21
|
-
)
|
|
28
|
+
NumberRangeCodec.numberRange = Base.define(8, writeNumberRange, readNumberRange, {
|
|
29
|
+
_typeCheck = "NumberRange",
|
|
30
|
+
})
|
|
22
31
|
|
|
23
32
|
return table.freeze(NumberRangeCodec)
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
--!strict
|
|
2
2
|
--!optimize 2
|
|
3
|
-
-- Ray codec. 24 bytes:
|
|
3
|
+
-- Ray codec. 24 bytes: Origin (3x f32) + Direction (3x f32).
|
|
4
4
|
|
|
5
5
|
local Base = require(script.Parent.Parent.Base)
|
|
6
6
|
|
|
7
|
-
--
|
|
7
|
+
-- Private ----------------------------------------------------------------
|
|
8
8
|
|
|
9
|
-
local
|
|
10
|
-
|
|
11
|
-
RayCodec.ray = Base.define(24, function(b: buffer, off: number, value: Ray): ()
|
|
9
|
+
local function writeRay(b: buffer, off: number, value: Ray): ()
|
|
12
10
|
local o = value.Origin
|
|
13
11
|
local d = value.Direction
|
|
14
12
|
buffer.writef32(b, off, o.X)
|
|
@@ -17,7 +15,9 @@ RayCodec.ray = Base.define(24, function(b: buffer, off: number, value: Ray): ()
|
|
|
17
15
|
buffer.writef32(b, off + 12, d.X)
|
|
18
16
|
buffer.writef32(b, off + 16, d.Y)
|
|
19
17
|
buffer.writef32(b, off + 20, d.Z)
|
|
20
|
-
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
local function readRay(b: buffer, off: number): Ray
|
|
21
21
|
return Ray.new(
|
|
22
22
|
Vector3.new(buffer.readf32(b, off), buffer.readf32(b, off + 4), buffer.readf32(b, off + 8)),
|
|
23
23
|
Vector3.new(
|
|
@@ -26,6 +26,12 @@ end, function(b: buffer, off: number): Ray
|
|
|
26
26
|
buffer.readf32(b, off + 20)
|
|
27
27
|
)
|
|
28
28
|
)
|
|
29
|
-
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
-- Public -----------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
local RayCodec = {}
|
|
34
|
+
|
|
35
|
+
RayCodec.ray = Base.define(24, writeRay, readRay, { _typeCheck = "Ray" })
|
|
30
36
|
|
|
31
37
|
return table.freeze(RayCodec)
|
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
--!strict
|
|
2
2
|
--!optimize 2
|
|
3
|
-
-- Rect codec. 16 bytes: 4x f32.
|
|
3
|
+
-- Rect codec. 16 bytes: 4x f32 (Min.X, Min.Y, Max.X, Max.Y).
|
|
4
4
|
|
|
5
5
|
local Base = require(script.Parent.Parent.Base)
|
|
6
6
|
|
|
7
|
-
--
|
|
7
|
+
-- Private ----------------------------------------------------------------
|
|
8
8
|
|
|
9
|
-
local
|
|
10
|
-
|
|
11
|
-
RectCodec.rect = Base.define(16, function(b: buffer, off: number, value: Rect): ()
|
|
9
|
+
local function writeRect(b: buffer, off: number, value: Rect): ()
|
|
12
10
|
buffer.writef32(b, off, value.Min.X)
|
|
13
11
|
buffer.writef32(b, off + 4, value.Min.Y)
|
|
14
12
|
buffer.writef32(b, off + 8, value.Max.X)
|
|
15
13
|
buffer.writef32(b, off + 12, value.Max.Y)
|
|
16
|
-
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
local function readRect(b: buffer, off: number): Rect
|
|
17
17
|
return Rect.new(
|
|
18
18
|
buffer.readf32(b, off),
|
|
19
19
|
buffer.readf32(b, off + 4),
|
|
20
20
|
buffer.readf32(b, off + 8),
|
|
21
21
|
buffer.readf32(b, off + 12)
|
|
22
22
|
)
|
|
23
|
-
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
-- Public -----------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
local RectCodec = {}
|
|
28
|
+
|
|
29
|
+
RectCodec.rect = Base.define(16, writeRect, readRect, { _typeCheck = "Rect" })
|
|
24
30
|
|
|
25
31
|
return table.freeze(RectCodec)
|
|
@@ -3,23 +3,14 @@
|
|
|
3
3
|
-- Region3 (24 bytes) and Region3int16 (12 bytes) codecs.
|
|
4
4
|
|
|
5
5
|
local Base = require(script.Parent.Parent.Base)
|
|
6
|
+
local Signed = require(script.Parent.Parent.primitive.Signed)
|
|
6
7
|
|
|
7
|
-
-- Private
|
|
8
|
+
-- Private ----------------------------------------------------------------
|
|
8
9
|
|
|
9
|
-
local
|
|
10
|
-
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
local function readI16(b: buffer, off: number): number
|
|
14
|
-
local raw = buffer.readu16(b, off)
|
|
15
|
-
return if raw >= 0x8000 then raw - 0x10000 else raw
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
-- Public --------------------------------------------------------------
|
|
10
|
+
local writeI16 = Signed.writeI16
|
|
11
|
+
local readi16 = buffer.readi16
|
|
19
12
|
|
|
20
|
-
local
|
|
21
|
-
|
|
22
|
-
RegionCodec.region3 = Base.define(24, function(b: buffer, off: number, value: Region3): ()
|
|
13
|
+
local function writeRegion3(b: buffer, off: number, value: Region3): ()
|
|
23
14
|
local pos = value.CFrame.Position
|
|
24
15
|
local half = value.Size * 0.5
|
|
25
16
|
local minV = pos - half
|
|
@@ -30,7 +21,9 @@ RegionCodec.region3 = Base.define(24, function(b: buffer, off: number, value: Re
|
|
|
30
21
|
buffer.writef32(b, off + 12, maxV.X)
|
|
31
22
|
buffer.writef32(b, off + 16, maxV.Y)
|
|
32
23
|
buffer.writef32(b, off + 20, maxV.Z)
|
|
33
|
-
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
local function readRegion3(b: buffer, off: number): Region3
|
|
34
27
|
return Region3.new(
|
|
35
28
|
Vector3.new(buffer.readf32(b, off), buffer.readf32(b, off + 4), buffer.readf32(b, off + 8)),
|
|
36
29
|
Vector3.new(
|
|
@@ -39,9 +32,9 @@ end, function(b: buffer, off: number): Region3
|
|
|
39
32
|
buffer.readf32(b, off + 20)
|
|
40
33
|
)
|
|
41
34
|
)
|
|
42
|
-
end
|
|
35
|
+
end
|
|
43
36
|
|
|
44
|
-
|
|
37
|
+
local function writeRegion3I16(b: buffer, off: number, value: Region3int16): ()
|
|
45
38
|
local minV = value.Min
|
|
46
39
|
local maxV = value.Max
|
|
47
40
|
writeI16(b, off, minV.X)
|
|
@@ -50,11 +43,21 @@ RegionCodec.region3int16 = Base.define(12, function(b: buffer, off: number, valu
|
|
|
50
43
|
writeI16(b, off + 6, maxV.X)
|
|
51
44
|
writeI16(b, off + 8, maxV.Y)
|
|
52
45
|
writeI16(b, off + 10, maxV.Z)
|
|
53
|
-
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
local function readRegion3I16(b: buffer, off: number): Region3int16
|
|
54
49
|
return Region3int16.new(
|
|
55
|
-
Vector3int16.new(
|
|
56
|
-
Vector3int16.new(
|
|
50
|
+
Vector3int16.new(readi16(b, off), readi16(b, off + 2), readi16(b, off + 4)),
|
|
51
|
+
Vector3int16.new(readi16(b, off + 6), readi16(b, off + 8), readi16(b, off + 10))
|
|
57
52
|
)
|
|
58
|
-
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
-- Public -----------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
local Region = {}
|
|
58
|
+
|
|
59
|
+
Region.region3 = Base.define(24, writeRegion3, readRegion3, { _typeCheck = "Region3" })
|
|
60
|
+
Region.region3int16 =
|
|
61
|
+
Base.define(12, writeRegion3I16, readRegion3I16, { _typeCheck = "Region3int16" })
|
|
59
62
|
|
|
60
|
-
return table.freeze(
|
|
63
|
+
return table.freeze(Region)
|
|
@@ -1,136 +1,162 @@
|
|
|
1
1
|
--!strict
|
|
2
2
|
--!optimize 2
|
|
3
|
-
-- NumberSequence and ColorSequence codecs
|
|
3
|
+
-- NumberSequence (12B/keypoint) and ColorSequence (7B/keypoint) codecs.
|
|
4
4
|
|
|
5
5
|
local Base = require(script.Parent.Parent.Base)
|
|
6
6
|
local Types = require(script.Parent.Parent.Parent.Types)
|
|
7
7
|
local Varint = require(script.Parent.Parent.primitive.Varint)
|
|
8
8
|
|
|
9
|
-
--
|
|
9
|
+
-- Constants --------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
local NUMSEQ_KP_BYTES = 12
|
|
12
|
+
local COLSEQ_KP_BYTES = 7
|
|
13
|
+
local MAX_KEYPOINTS = 20
|
|
14
|
+
|
|
15
|
+
-- Private ----------------------------------------------------------------
|
|
10
16
|
|
|
11
17
|
local alloc = Base.alloc
|
|
12
18
|
local round = math.round
|
|
13
19
|
local clamp = math.clamp
|
|
14
20
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
local
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
local
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
21
|
+
local function writeNumberSequence(ch: Types.ChannelState, value: NumberSequence): ()
|
|
22
|
+
local keypoints = value.Keypoints
|
|
23
|
+
local count = #keypoints
|
|
24
|
+
Varint.write(ch, count)
|
|
25
|
+
if count == 0 then
|
|
26
|
+
return
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
local bytes = count * NUMSEQ_KP_BYTES
|
|
30
|
+
local cursor = ch.cursor
|
|
31
|
+
if cursor + bytes > ch.size then
|
|
32
|
+
alloc(ch, bytes)
|
|
33
|
+
end
|
|
34
|
+
local b = ch.buff
|
|
35
|
+
|
|
36
|
+
local off = cursor
|
|
37
|
+
for i = 1, count do
|
|
38
|
+
local kp = keypoints[i]
|
|
39
|
+
buffer.writef32(b, off, kp.Time)
|
|
40
|
+
buffer.writef32(b, off + 4, kp.Value)
|
|
41
|
+
buffer.writef32(b, off + 8, kp.Envelope)
|
|
42
|
+
off += NUMSEQ_KP_BYTES
|
|
43
|
+
end
|
|
44
|
+
ch.cursor = cursor + bytes
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
local function readNumberSequence(
|
|
48
|
+
src: buffer,
|
|
49
|
+
pos: number,
|
|
50
|
+
_refs: { Instance }?
|
|
51
|
+
): (NumberSequence, number)
|
|
52
|
+
local count, lenBytes = Varint.read(src, pos)
|
|
53
|
+
if count == 0 then
|
|
54
|
+
return NumberSequence.new(0), lenBytes
|
|
55
|
+
end
|
|
56
|
+
if count > MAX_KEYPOINTS then
|
|
57
|
+
error(
|
|
58
|
+
`[Lync] NumberSequence.read: keypoint count {count} exceeds Roblox limit {MAX_KEYPOINTS}`
|
|
59
|
+
)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
local bytes = count * NUMSEQ_KP_BYTES
|
|
63
|
+
local dataStart = pos + lenBytes
|
|
64
|
+
if dataStart + bytes > buffer.len(src) then
|
|
65
|
+
error("[Lync] NumberSequence.read: data exceeds buffer")
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
local keypoints = table.create(count)
|
|
69
|
+
local off = dataStart
|
|
70
|
+
for i = 1, count do
|
|
71
|
+
keypoints[i] = NumberSequenceKeypoint.new(
|
|
72
|
+
buffer.readf32(src, off),
|
|
73
|
+
buffer.readf32(src, off + 4),
|
|
74
|
+
buffer.readf32(src, off + 8)
|
|
75
|
+
)
|
|
76
|
+
off += NUMSEQ_KP_BYTES
|
|
77
|
+
end
|
|
78
|
+
return NumberSequence.new(keypoints), lenBytes + bytes
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
local function writeColorSequence(ch: Types.ChannelState, value: ColorSequence): ()
|
|
82
|
+
local keypoints = value.Keypoints
|
|
83
|
+
local count = #keypoints
|
|
84
|
+
Varint.write(ch, count)
|
|
85
|
+
if count == 0 then
|
|
86
|
+
return
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
local bytes = count * COLSEQ_KP_BYTES
|
|
90
|
+
local cursor = ch.cursor
|
|
91
|
+
if cursor + bytes > ch.size then
|
|
92
|
+
alloc(ch, bytes)
|
|
93
|
+
end
|
|
94
|
+
local b = ch.buff
|
|
95
|
+
|
|
96
|
+
local off = cursor
|
|
97
|
+
for i = 1, count do
|
|
98
|
+
local kp = keypoints[i]
|
|
99
|
+
local c = kp.Value
|
|
100
|
+
buffer.writef32(b, off, kp.Time)
|
|
101
|
+
buffer.writeu8(b, off + 4, round(clamp(c.R, 0, 1) * 255))
|
|
102
|
+
buffer.writeu8(b, off + 5, round(clamp(c.G, 0, 1) * 255))
|
|
103
|
+
buffer.writeu8(b, off + 6, round(clamp(c.B, 0, 1) * 255))
|
|
104
|
+
off += COLSEQ_KP_BYTES
|
|
105
|
+
end
|
|
106
|
+
ch.cursor = cursor + bytes
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
local function readColorSequence(
|
|
110
|
+
src: buffer,
|
|
111
|
+
pos: number,
|
|
112
|
+
_refs: { Instance }?
|
|
113
|
+
): (ColorSequence, number)
|
|
114
|
+
local count, lenBytes = Varint.read(src, pos)
|
|
115
|
+
if count == 0 then
|
|
116
|
+
return ColorSequence.new(Color3.new()), lenBytes
|
|
117
|
+
end
|
|
118
|
+
if count > MAX_KEYPOINTS then
|
|
119
|
+
error(
|
|
120
|
+
`[Lync] ColorSequence.read: keypoint count {count} exceeds Roblox limit {MAX_KEYPOINTS}`
|
|
121
|
+
)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
local bytes = count * COLSEQ_KP_BYTES
|
|
125
|
+
local dataStart = pos + lenBytes
|
|
126
|
+
if dataStart + bytes > buffer.len(src) then
|
|
127
|
+
error("[Lync] ColorSequence.read: data exceeds buffer")
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
local keypoints = table.create(count)
|
|
131
|
+
local off = dataStart
|
|
132
|
+
for i = 1, count do
|
|
133
|
+
keypoints[i] = ColorSequenceKeypoint.new(
|
|
134
|
+
buffer.readf32(src, off),
|
|
135
|
+
Color3.fromRGB(
|
|
136
|
+
buffer.readu8(src, off + 4),
|
|
137
|
+
buffer.readu8(src, off + 5),
|
|
138
|
+
buffer.readu8(src, off + 6)
|
|
68
139
|
)
|
|
69
|
-
|
|
140
|
+
)
|
|
141
|
+
off += COLSEQ_KP_BYTES
|
|
142
|
+
end
|
|
143
|
+
return ColorSequence.new(keypoints), lenBytes + bytes
|
|
144
|
+
end
|
|
70
145
|
|
|
71
|
-
|
|
72
|
-
end,
|
|
73
|
-
} :: any)
|
|
146
|
+
-- Public -----------------------------------------------------------------
|
|
74
147
|
|
|
75
|
-
|
|
76
|
-
_typeCheck = "ColorSequence",
|
|
148
|
+
local Sequence = {}
|
|
77
149
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if count == 0 then
|
|
84
|
-
return
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
local bytes = count * 7
|
|
88
|
-
local cursor = ch.cursor
|
|
89
|
-
if cursor + bytes > ch.size then
|
|
90
|
-
alloc(ch, bytes)
|
|
91
|
-
end
|
|
92
|
-
local b = ch.buff
|
|
93
|
-
|
|
94
|
-
for i = 1, count do
|
|
95
|
-
local kp = keypoints[i]
|
|
96
|
-
local off = cursor + (i - 1) * 7
|
|
97
|
-
local c = kp.Value
|
|
98
|
-
buffer.writef32(b, off, kp.Time)
|
|
99
|
-
buffer.writeu8(b, off + 4, round(clamp(c.R, 0, 1) * 255))
|
|
100
|
-
buffer.writeu8(b, off + 5, round(clamp(c.G, 0, 1) * 255))
|
|
101
|
-
buffer.writeu8(b, off + 6, round(clamp(c.B, 0, 1) * 255))
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
ch.cursor = cursor + bytes
|
|
105
|
-
end,
|
|
106
|
-
|
|
107
|
-
read = function(src: buffer, pos: number, _refs: { Instance }?): (ColorSequence, number)
|
|
108
|
-
local count, lenBytes = Varint.read(src, pos)
|
|
109
|
-
if count == 0 then
|
|
110
|
-
return ColorSequence.new(Color3.new()), lenBytes
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
local bytes = count * 7
|
|
114
|
-
local dataStart = pos + lenBytes
|
|
115
|
-
if dataStart + bytes > buffer.len(src) then
|
|
116
|
-
error("[Lync] ColorSequence: data exceeds buffer")
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
local keypoints = table.create(count)
|
|
120
|
-
for i = 1, count do
|
|
121
|
-
local off = dataStart + (i - 1) * 7
|
|
122
|
-
keypoints[i] = ColorSequenceKeypoint.new(
|
|
123
|
-
buffer.readf32(src, off),
|
|
124
|
-
Color3.fromRGB(
|
|
125
|
-
buffer.readu8(src, off + 4),
|
|
126
|
-
buffer.readu8(src, off + 5),
|
|
127
|
-
buffer.readu8(src, off + 6)
|
|
128
|
-
)
|
|
129
|
-
)
|
|
130
|
-
end
|
|
150
|
+
Sequence.numberSequence = table.freeze({
|
|
151
|
+
_typeCheck = "NumberSequence",
|
|
152
|
+
write = writeNumberSequence,
|
|
153
|
+
read = readNumberSequence,
|
|
154
|
+
})
|
|
131
155
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
156
|
+
Sequence.colorSequence = table.freeze({
|
|
157
|
+
_typeCheck = "ColorSequence",
|
|
158
|
+
write = writeColorSequence,
|
|
159
|
+
read = readColorSequence,
|
|
160
|
+
})
|
|
135
161
|
|
|
136
|
-
return table.freeze(
|
|
162
|
+
return table.freeze(Sequence)
|