@axpecter/lync 2.3.2 → 3.0.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/LICENSE +21 -0
- package/README.md +302 -299
- package/Types.luau +215 -0
- package/api/Define.luau +154 -0
- package/api/Lifecycle.luau +119 -0
- package/api/Packet.luau +108 -0
- package/api/Query.luau +149 -0
- package/api/Set.luau +189 -0
- package/channel/Blocks.luau +124 -0
- package/channel/Group.luau +118 -0
- package/channel/Link.luau +135 -0
- package/channel/Outbox.luau +261 -0
- package/channel/Recipients.luau +129 -0
- package/channel/Transport.luau +138 -0
- package/codec/Base.luau +236 -0
- package/codec/Composites.luau +128 -0
- package/codec/Datatypes.luau +162 -0
- package/codec/Legality.luau +61 -0
- package/codec/Scalars.luau +72 -0
- package/codec/Text.luau +89 -0
- package/codec/init.luau +39 -0
- package/index.d.ts +285 -0
- package/init.luau +91 -0
- package/kernel/Bits.luau +16 -0
- package/kernel/Catalog.luau +121 -0
- package/kernel/Heap.luau +80 -0
- package/kernel/Listeners.luau +95 -0
- package/kernel/Log.luau +197 -0
- package/kernel/Tally.luau +128 -0
- package/kernel/Threads.luau +44 -0
- package/kernel/Wide.luau +267 -0
- package/package.json +15 -32
- package/runtime/Boundary.luau +180 -0
- package/runtime/Dispatch.luau +91 -0
- package/runtime/Handles.luau +114 -0
- package/runtime/Handshake.luau +90 -0
- package/runtime/Pending.luau +196 -0
- package/runtime/Router.luau +379 -0
- package/runtime/Session.luau +731 -0
- package/shape/Compile.luau +340 -0
- package/shape/Folds.luau +332 -0
- package/shape/Frames.luau +170 -0
- package/shape/Grid.luau +169 -0
- package/shape/Ir.luau +540 -0
- package/shape/Joins.luau +125 -0
- package/shape/Legality.luau +273 -0
- package/shape/Lower.luau +419 -0
- package/shape/Order.luau +64 -0
- package/shape/Regions.luau +113 -0
- package/shape/Rotation.luau +472 -0
- package/shape/Serial.luau +258 -0
- package/shape/Words.luau +89 -0
- package/shape/emit/Block.luau +453 -0
- package/shape/emit/Column.luau +338 -0
- package/shape/emit/Leaf.luau +462 -0
- package/shape/emit/Word.luau +234 -0
- package/shape/emit/init.luau +222 -0
- package/shape/init.luau +78 -0
- package/state/Apply.luau +330 -0
- package/state/Audience.luau +126 -0
- package/state/Catchup.luau +218 -0
- package/state/Coalesce.luau +43 -0
- package/state/Fieldset.luau +177 -0
- package/state/Newest.luau +339 -0
- package/state/Plan.luau +441 -0
- package/state/Sections.luau +468 -0
- package/state/Store.luau +188 -0
- package/state/Sync.luau +762 -0
- package/wire/Bytes.luau +118 -0
- package/wire/Clock.luau +37 -0
- package/wire/Protocol.luau +110 -0
- package/wire/Sequence.luau +40 -0
- package/wire/Varint.luau +124 -0
- package/src/Types.luau +0 -180
- package/src/api/Group.luau +0 -156
- package/src/api/Packet.luau +0 -319
- package/src/api/Query.luau +0 -338
- package/src/api/Scope.luau +0 -90
- package/src/api/Signal.luau +0 -188
- package/src/codec/Base.luau +0 -136
- package/src/codec/composite/Array.luau +0 -456
- package/src/codec/composite/Map.luau +0 -469
- package/src/codec/composite/Optional.luau +0 -54
- package/src/codec/composite/Shared.luau +0 -291
- package/src/codec/composite/Struct.luau +0 -494
- package/src/codec/composite/Tagged.luau +0 -103
- package/src/codec/composite/Tuple.luau +0 -143
- package/src/codec/datatype/Buffer.luau +0 -66
- package/src/codec/datatype/CFrame.luau +0 -109
- package/src/codec/datatype/Color.luau +0 -32
- package/src/codec/datatype/Instance.luau +0 -52
- package/src/codec/datatype/IntVector.luau +0 -39
- package/src/codec/datatype/NumberRange.luau +0 -39
- package/src/codec/datatype/Ray.luau +0 -36
- package/src/codec/datatype/Rect.luau +0 -31
- package/src/codec/datatype/Region.luau +0 -62
- package/src/codec/datatype/Sequence.luau +0 -184
- package/src/codec/datatype/String.luau +0 -94
- package/src/codec/datatype/UDim.luau +0 -46
- package/src/codec/datatype/Vector.luau +0 -130
- package/src/codec/meta/Auto.luau +0 -318
- package/src/codec/meta/Bitfield.luau +0 -147
- package/src/codec/meta/Custom.luau +0 -33
- package/src/codec/meta/DeltaScalar.luau +0 -390
- package/src/codec/meta/Enum.luau +0 -50
- package/src/codec/meta/Float.luau +0 -38
- package/src/codec/meta/Nothing.luau +0 -13
- package/src/codec/meta/Unknown.luau +0 -41
- package/src/codec/primitive/Bool.luau +0 -26
- package/src/codec/primitive/Float16.luau +0 -99
- package/src/codec/primitive/Int.luau +0 -59
- package/src/codec/primitive/Number.luau +0 -24
- package/src/codec/primitive/Signed.luau +0 -32
- package/src/codec/primitive/Varint.luau +0 -165
- package/src/codec/primitive/Zint.luau +0 -99
- package/src/index.d.ts +0 -423
- package/src/init.luau +0 -362
- package/src/internal/Baseline.luau +0 -57
- package/src/internal/Channel.luau +0 -390
- package/src/internal/Middleware.luau +0 -100
- package/src/internal/Pool.luau +0 -65
- package/src/internal/Registry.luau +0 -119
- package/src/internal/Transport.luau +0 -28
- package/src/transport/Bridge.luau +0 -110
- package/src/transport/Client.luau +0 -97
- package/src/transport/Gate.luau +0 -488
- package/src/transport/Reader.luau +0 -331
- package/src/transport/Server.luau +0 -211
- package/src/util/Array.luau +0 -18
- package/src/util/Buffer.luau +0 -90
- package/src/util/Constants.luau +0 -30
- package/src/util/Log.luau +0 -68
- package/src/util/Player.luau +0 -14
- package/src/util/Quantize.luau +0 -84
- package/src/util/Quat.luau +0 -124
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
--!strict
|
|
2
|
-
--!optimize 2
|
|
3
|
-
-- Range-typed integer codec. Picks the narrowest u8/u16/u32/i8/i16/i32 form.
|
|
4
|
-
|
|
5
|
-
local Base = require(script.Parent.Parent.Base)
|
|
6
|
-
local Log = require(script.Parent.Parent.Parent.util.Log)
|
|
7
|
-
local Signed = require(script.Parent.Signed)
|
|
8
|
-
local Types = require(script.Parent.Parent.Parent.Types)
|
|
9
|
-
|
|
10
|
-
-- Private ----------------------------------------------------------------
|
|
11
|
-
|
|
12
|
-
local floor = math.floor
|
|
13
|
-
local writeI8 = Signed.writeI8
|
|
14
|
-
local writeI16 = Signed.writeI16
|
|
15
|
-
local writeI32 = Signed.writeI32
|
|
16
|
-
|
|
17
|
-
-- Public -----------------------------------------------------------------
|
|
18
|
-
|
|
19
|
-
local Int = {}
|
|
20
|
-
|
|
21
|
-
function Int.int(min: number, max: number): Types.InternalCodec<number>
|
|
22
|
-
if min > max then
|
|
23
|
-
Log.error(`min ({min}) must be <= max ({max})`)
|
|
24
|
-
end
|
|
25
|
-
Log.assert(floor(min) == min and floor(max) == max, "bounds must be integers")
|
|
26
|
-
|
|
27
|
-
local meta = {
|
|
28
|
-
_min = min,
|
|
29
|
-
_max = max,
|
|
30
|
-
_isInteger = true,
|
|
31
|
-
_typeCheck = "number",
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if min >= 0 then
|
|
35
|
-
if max <= 0xFF then
|
|
36
|
-
return Base.define(1, buffer.writeu8, buffer.readu8, meta)
|
|
37
|
-
end
|
|
38
|
-
if max <= 0xFFFF then
|
|
39
|
-
return Base.define(2, buffer.writeu16, buffer.readu16, meta)
|
|
40
|
-
end
|
|
41
|
-
if max <= 0xFFFFFFFF then
|
|
42
|
-
return Base.define(4, buffer.writeu32, buffer.readu32, meta)
|
|
43
|
-
end
|
|
44
|
-
else
|
|
45
|
-
if min >= -0x80 and max <= 0x7F then
|
|
46
|
-
return Base.define(1, writeI8, buffer.readi8, meta)
|
|
47
|
-
end
|
|
48
|
-
if min >= -0x8000 and max <= 0x7FFF then
|
|
49
|
-
return Base.define(2, writeI16, buffer.readi16, meta)
|
|
50
|
-
end
|
|
51
|
-
if min >= -0x80000000 and max <= 0x7FFFFFFF then
|
|
52
|
-
return Base.define(4, writeI32, buffer.readi32, meta)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
Log.error(`range [{min}, {max}] exceeds i32 bounds`)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
return table.freeze(Int)
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
--!strict
|
|
2
|
-
--!optimize 2
|
|
3
|
-
-- Explicit-precision float codecs: f32 (4B) and f64 (8B).
|
|
4
|
-
|
|
5
|
-
local Base = require(script.Parent.Parent.Base)
|
|
6
|
-
|
|
7
|
-
-- State ------------------------------------------------------------------
|
|
8
|
-
|
|
9
|
-
--[[
|
|
10
|
-
Roblox is single-threaded, so a module-level scratch is safe to alias.
|
|
11
|
-
Auto codec uses this to round-trip a float through f32 and check fidelity.
|
|
12
|
-
]]
|
|
13
|
-
local F32_SCRATCH = buffer.create(4)
|
|
14
|
-
|
|
15
|
-
-- Public -----------------------------------------------------------------
|
|
16
|
-
|
|
17
|
-
local Number = {}
|
|
18
|
-
|
|
19
|
-
Number.f32 = Base.define(4, buffer.writef32, buffer.readf32, { _typeCheck = "number" })
|
|
20
|
-
Number.f64 = Base.define(8, buffer.writef64, buffer.readf64, { _typeCheck = "number" })
|
|
21
|
-
|
|
22
|
-
Number._f32Scratch = F32_SCRATCH
|
|
23
|
-
|
|
24
|
-
return table.freeze(Number)
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
--!strict
|
|
2
|
-
--!native
|
|
3
|
-
-- Signed integer writers via writeu* + two's complement (writei* is not FASTCALL).
|
|
4
|
-
|
|
5
|
-
-- Private ----------------------------------------------------------------
|
|
6
|
-
|
|
7
|
-
local writeu8 = buffer.writeu8
|
|
8
|
-
local writeu16 = buffer.writeu16
|
|
9
|
-
local writeu32 = buffer.writeu32
|
|
10
|
-
|
|
11
|
-
-- Public -----------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
local Signed = {}
|
|
14
|
-
|
|
15
|
-
function Signed.writeI8(b: buffer, off: number, value: number): ()
|
|
16
|
-
writeu8(b, off, if value < 0 then value + 0x100 else value)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
function Signed.writeI16(b: buffer, off: number, value: number): ()
|
|
20
|
-
writeu16(b, off, if value < 0 then value + 0x10000 else value)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
function Signed.writeI32(b: buffer, off: number, value: number): ()
|
|
24
|
-
writeu32(b, off, if value < 0 then value + 0x100000000 else value)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
-- Reads stay on buffer.readi* (already FASTCALL).
|
|
28
|
-
Signed.readI8 = buffer.readi8
|
|
29
|
-
Signed.readI16 = buffer.readi16
|
|
30
|
-
Signed.readI32 = buffer.readi32
|
|
31
|
-
|
|
32
|
-
return table.freeze(Signed)
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
--!strict
|
|
2
|
-
--!native
|
|
3
|
-
-- Dense prefix varint over [0, 2^32 - 1]. Single-branch decode.
|
|
4
|
-
|
|
5
|
-
local Base = require(script.Parent.Parent.Base)
|
|
6
|
-
local Constants = require(script.Parent.Parent.Parent.util.Constants)
|
|
7
|
-
local Log = require(script.Parent.Parent.Parent.util.Log)
|
|
8
|
-
local Types = require(script.Parent.Parent.Parent.Types)
|
|
9
|
-
|
|
10
|
-
-- Constants --------------------------------------------------------------
|
|
11
|
-
|
|
12
|
-
--[[
|
|
13
|
-
Wire layout (first byte tag selects length):
|
|
14
|
-
0x00..0xBF 1 byte value = b0 [0..191]
|
|
15
|
-
0xC0..0xDF 2 bytes value = (b0 & 0x1F)<<8 | b1 + 192 [192..8383]
|
|
16
|
-
0xE0..0xEF 3 bytes value = (b0 & 0x0F)<<16 | u16 + 8384 [8384..1056959]
|
|
17
|
-
0xF0..0xFF 5 bytes value = u32 [..0xFFFFFFFF]
|
|
18
|
-
]]
|
|
19
|
-
local INLINE_MAX = 0xBF
|
|
20
|
-
local TWO_TAG = 0xC0
|
|
21
|
-
local TWO_END = 0xDF
|
|
22
|
-
local TWO_MASK = 0x1F
|
|
23
|
-
local THREE_TAG = 0xE0
|
|
24
|
-
local THREE_END = 0xEF
|
|
25
|
-
local THREE_MASK = 0x0F
|
|
26
|
-
local FIVE_TAG = 0xF0
|
|
27
|
-
local TWO_MAX = 8383
|
|
28
|
-
local THREE_MAX = 1056959
|
|
29
|
-
local TWO_BIAS = 192
|
|
30
|
-
local THREE_BIAS = 8384
|
|
31
|
-
|
|
32
|
-
local U8_MAX = Constants.U8_MAX
|
|
33
|
-
local U16_MAX = Constants.U16_MAX
|
|
34
|
-
local U32_MAX = Constants.U32_MAX
|
|
35
|
-
|
|
36
|
-
-- Private ----------------------------------------------------------------
|
|
37
|
-
|
|
38
|
-
local ensure = Base.ensure
|
|
39
|
-
local band = bit32.band
|
|
40
|
-
local bor = bit32.bor
|
|
41
|
-
local rshift = bit32.rshift
|
|
42
|
-
local writeu8 = buffer.writeu8
|
|
43
|
-
local writeu16 = buffer.writeu16
|
|
44
|
-
local writeu32 = buffer.writeu32
|
|
45
|
-
local readu8 = buffer.readu8
|
|
46
|
-
local readu16 = buffer.readu16
|
|
47
|
-
local readu32 = buffer.readu32
|
|
48
|
-
|
|
49
|
-
-- Public -----------------------------------------------------------------
|
|
50
|
-
|
|
51
|
-
local Varint = {}
|
|
52
|
-
|
|
53
|
-
Varint.INLINE_MAX = INLINE_MAX
|
|
54
|
-
|
|
55
|
-
-- Wire byte count for a value, without encoding it. Used by cost heuristics.
|
|
56
|
-
function Varint.length(value: number): number
|
|
57
|
-
if value <= INLINE_MAX then
|
|
58
|
-
return 1
|
|
59
|
-
elseif value <= TWO_MAX then
|
|
60
|
-
return 2
|
|
61
|
-
elseif value <= THREE_MAX then
|
|
62
|
-
return 3
|
|
63
|
-
end
|
|
64
|
-
return 5
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
function Varint.write(ch: Types.ChannelState, value: number): ()
|
|
68
|
-
if value < 0 or value > U32_MAX or value % 1 ~= 0 then
|
|
69
|
-
Log.error(`value must be an integer in [0, {U32_MAX}], got {value}`)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
if value <= INLINE_MAX then
|
|
73
|
-
ensure(ch, 1)
|
|
74
|
-
local cursor = ch.cursor
|
|
75
|
-
writeu8(ch.buff, cursor, value)
|
|
76
|
-
ch.cursor = cursor + 1
|
|
77
|
-
return
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
if value <= TWO_MAX then
|
|
81
|
-
ensure(ch, 2)
|
|
82
|
-
local cursor = ch.cursor
|
|
83
|
-
local adjusted = value - TWO_BIAS
|
|
84
|
-
local b = ch.buff
|
|
85
|
-
writeu8(b, cursor, bor(TWO_TAG, rshift(adjusted, 8)))
|
|
86
|
-
writeu8(b, cursor + 1, band(adjusted, U8_MAX))
|
|
87
|
-
ch.cursor = cursor + 2
|
|
88
|
-
return
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
if value <= THREE_MAX then
|
|
92
|
-
ensure(ch, 3)
|
|
93
|
-
local cursor = ch.cursor
|
|
94
|
-
local adjusted = value - THREE_BIAS
|
|
95
|
-
local b = ch.buff
|
|
96
|
-
writeu8(b, cursor, bor(THREE_TAG, rshift(adjusted, 16)))
|
|
97
|
-
writeu16(b, cursor + 1, band(adjusted, U16_MAX))
|
|
98
|
-
ch.cursor = cursor + 3
|
|
99
|
-
return
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
ensure(ch, 5)
|
|
103
|
-
local cursor = ch.cursor
|
|
104
|
-
local b = ch.buff
|
|
105
|
-
writeu8(b, cursor, FIVE_TAG)
|
|
106
|
-
writeu32(b, cursor + 1, value)
|
|
107
|
-
ch.cursor = cursor + 5
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
--[[
|
|
111
|
-
Returns (value, bytesConsumed). On insufficient bytes returns (0, 0) so
|
|
112
|
-
the transport can abort the frame instead of letting the buffer access
|
|
113
|
-
raise — required for recovery from truncated/desynced incoming buffers.
|
|
114
|
-
]]
|
|
115
|
-
function Varint.read(src: buffer, pos: number): (number, number)
|
|
116
|
-
local available = buffer.len(src) - pos
|
|
117
|
-
if available < 1 then
|
|
118
|
-
return 0, 0
|
|
119
|
-
end
|
|
120
|
-
local b0 = readu8(src, pos)
|
|
121
|
-
if b0 <= INLINE_MAX then
|
|
122
|
-
return b0, 1
|
|
123
|
-
end
|
|
124
|
-
if b0 <= TWO_END then
|
|
125
|
-
if available < 2 then
|
|
126
|
-
return 0, 0
|
|
127
|
-
end
|
|
128
|
-
return band(b0, TWO_MASK) * 256 + readu8(src, pos + 1) + TWO_BIAS, 2
|
|
129
|
-
end
|
|
130
|
-
if b0 <= THREE_END then
|
|
131
|
-
if available < 3 then
|
|
132
|
-
return 0, 0
|
|
133
|
-
end
|
|
134
|
-
return band(b0, THREE_MASK) * 65536 + readu16(src, pos + 1) + THREE_BIAS, 3
|
|
135
|
-
end
|
|
136
|
-
if available < 5 then
|
|
137
|
-
return 0, 0
|
|
138
|
-
end
|
|
139
|
-
return readu32(src, pos + 1), 5
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
-- Caller-asserted: value is known to fit in INLINE_MAX.
|
|
143
|
-
function Varint.writeInline(ch: Types.ChannelState, value: number): ()
|
|
144
|
-
ensure(ch, 1)
|
|
145
|
-
local cursor = ch.cursor
|
|
146
|
-
writeu8(ch.buff, cursor, value)
|
|
147
|
-
ch.cursor = cursor + 1
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
--[[
|
|
151
|
-
Length-prefix decode that fast-paths the [0, INLINE_MAX] single-byte form
|
|
152
|
-
before falling through to full varint. Used by Buffer, String, and Auto.
|
|
153
|
-
]]
|
|
154
|
-
function Varint.readLengthPrefix(src: buffer, pos: number): (number, number)
|
|
155
|
-
if buffer.len(src) - pos < 1 then
|
|
156
|
-
return 0, 0
|
|
157
|
-
end
|
|
158
|
-
local b0 = readu8(src, pos)
|
|
159
|
-
if b0 <= INLINE_MAX then
|
|
160
|
-
return b0, 1
|
|
161
|
-
end
|
|
162
|
-
return Varint.read(src, pos)
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
return table.freeze(Varint)
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
--!strict
|
|
2
|
-
--!native
|
|
3
|
-
-- Signed varint via zigzag mapping. Small magnitudes pack in 1 byte.
|
|
4
|
-
|
|
5
|
-
local Log = require(script.Parent.Parent.Parent.util.Log)
|
|
6
|
-
local Types = require(script.Parent.Parent.Parent.Types)
|
|
7
|
-
local Varint = require(script.Parent.Parent.primitive.Varint)
|
|
8
|
-
|
|
9
|
-
-- Constants --------------------------------------------------------------
|
|
10
|
-
|
|
11
|
-
--[[
|
|
12
|
-
Zigzag fold maps signed values onto unsigned varint space:
|
|
13
|
-
n >= 0 -> 2n
|
|
14
|
-
n < 0 -> -2n - 1
|
|
15
|
-
Inverse: low bit selects sign, shift down 1 bit.
|
|
16
|
-
|
|
17
|
-
Wire ranges (using Varint dense form):
|
|
18
|
-
1 byte: [-96, 95]
|
|
19
|
-
2 bytes: [-4192, 4191]
|
|
20
|
-
3 bytes: [-528480, 528479]
|
|
21
|
-
5 bytes: full i32
|
|
22
|
-
]]
|
|
23
|
-
local I32_MIN = -0x80000000
|
|
24
|
-
local I32_MAX = 0x7FFFFFFF
|
|
25
|
-
|
|
26
|
-
-- Private ----------------------------------------------------------------
|
|
27
|
-
|
|
28
|
-
local floor = math.floor
|
|
29
|
-
local band = bit32.band
|
|
30
|
-
local varintWrite = Varint.write
|
|
31
|
-
local varintRead = Varint.read
|
|
32
|
-
|
|
33
|
-
-- Signed -> unsigned. Hot path; called per write of every delta scalar.
|
|
34
|
-
local function encode(value: number): number
|
|
35
|
-
if value >= 0 then
|
|
36
|
-
return value * 2
|
|
37
|
-
end
|
|
38
|
-
return value * -2 - 1
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
-- Inverse of encode. Even -> n/2; odd -> -((n+1)/2). Branchless on the half.
|
|
42
|
-
local function decode(raw: number): number
|
|
43
|
-
local low = band(raw, 1)
|
|
44
|
-
local half = (raw - low) / 2
|
|
45
|
-
return if low == 1 then -half - 1 else half
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
-- Public -----------------------------------------------------------------
|
|
49
|
-
|
|
50
|
-
local Zint = {}
|
|
51
|
-
|
|
52
|
-
Zint.encode = encode
|
|
53
|
-
Zint.decode = decode
|
|
54
|
-
|
|
55
|
-
--[[
|
|
56
|
-
Variable-length signed integer in [I32_MIN, I32_MAX]. Optional [min, max]
|
|
57
|
-
bounds gate input at write time so out-of-range payloads error early
|
|
58
|
-
rather than corrupting downstream decoders.
|
|
59
|
-
]]
|
|
60
|
-
function Zint.zint(min: number?, max: number?): Types.InternalCodec<number>
|
|
61
|
-
local lo = min or I32_MIN
|
|
62
|
-
local hi = max or I32_MAX
|
|
63
|
-
if lo > hi then
|
|
64
|
-
Log.error(`min ({lo}) must be <= max ({hi})`)
|
|
65
|
-
end
|
|
66
|
-
if floor(lo) ~= lo or floor(hi) ~= hi then
|
|
67
|
-
Log.error("bounds must be integers")
|
|
68
|
-
end
|
|
69
|
-
if lo < I32_MIN or hi > I32_MAX then
|
|
70
|
-
Log.error(`range [{lo}, {hi}] exceeds i32 bounds`)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
return table.freeze({
|
|
74
|
-
_typeCheck = "number",
|
|
75
|
-
_isInteger = true,
|
|
76
|
-
_min = lo,
|
|
77
|
-
_max = hi,
|
|
78
|
-
|
|
79
|
-
write = function(ch: Types.ChannelState, value: number): ()
|
|
80
|
-
if value < lo or value > hi then
|
|
81
|
-
Log.error(`value {value} out of range [{lo}, {hi}]`)
|
|
82
|
-
end
|
|
83
|
-
if floor(value) ~= value then
|
|
84
|
-
Log.error(`value {value} must be an integer`)
|
|
85
|
-
end
|
|
86
|
-
varintWrite(ch, encode(value))
|
|
87
|
-
end,
|
|
88
|
-
|
|
89
|
-
read = function(src: buffer, pos: number, _refs: { Instance }?): (number, number)
|
|
90
|
-
local raw, consumed = varintRead(src, pos)
|
|
91
|
-
if consumed == 0 then
|
|
92
|
-
Log.error("truncated zint")
|
|
93
|
-
end
|
|
94
|
-
return decode(raw), consumed
|
|
95
|
-
end,
|
|
96
|
-
}) :: Types.InternalCodec<number>
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
return table.freeze(Zint)
|