@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.
Files changed (52) hide show
  1. package/README.md +41 -2
  2. package/package.json +1 -1
  3. package/src/Types.luau +13 -1
  4. package/src/api/Group.luau +35 -28
  5. package/src/api/Namespace.luau +107 -89
  6. package/src/api/Packet.luau +69 -51
  7. package/src/api/Query.luau +101 -95
  8. package/src/api/Scope.luau +32 -18
  9. package/src/api/Signal.luau +78 -56
  10. package/src/codec/Base.luau +17 -17
  11. package/src/codec/composite/Array.luau +74 -74
  12. package/src/codec/composite/Map.luau +80 -80
  13. package/src/codec/composite/Optional.luau +14 -14
  14. package/src/codec/composite/Shared.luau +35 -35
  15. package/src/codec/composite/Struct.luau +108 -108
  16. package/src/codec/composite/Tagged.luau +71 -71
  17. package/src/codec/composite/Tuple.luau +35 -35
  18. package/src/codec/datatype/Buffer.luau +18 -18
  19. package/src/codec/datatype/CFrame.luau +24 -24
  20. package/src/codec/datatype/Color.luau +8 -12
  21. package/src/codec/datatype/Instance.luau +13 -13
  22. package/src/codec/datatype/IntVector.luau +17 -17
  23. package/src/codec/datatype/NumberRange.luau +7 -7
  24. package/src/codec/datatype/Ray.luau +16 -16
  25. package/src/codec/datatype/Rect.luau +13 -13
  26. package/src/codec/datatype/Region.luau +32 -36
  27. package/src/codec/datatype/Sequence.luau +41 -41
  28. package/src/codec/datatype/String.luau +28 -28
  29. package/src/codec/datatype/UDim.luau +17 -17
  30. package/src/codec/datatype/Vector.luau +14 -18
  31. package/src/codec/meta/Auto.luau +75 -73
  32. package/src/codec/meta/Bitfield.luau +46 -46
  33. package/src/codec/meta/Custom.luau +7 -7
  34. package/src/codec/meta/Enum.luau +25 -25
  35. package/src/codec/meta/Nothing.luau +3 -3
  36. package/src/codec/meta/Quantized.luau +63 -60
  37. package/src/codec/meta/Unknown.luau +11 -11
  38. package/src/codec/primitive/Bool.luau +12 -12
  39. package/src/codec/primitive/Float16.luau +28 -28
  40. package/src/codec/primitive/Number.luau +41 -41
  41. package/src/codec/primitive/Varint.luau +19 -19
  42. package/src/init.luau +81 -61
  43. package/src/internal/Baseline.luau +7 -7
  44. package/src/internal/Channel.luau +56 -56
  45. package/src/internal/Middleware.luau +29 -29
  46. package/src/internal/Pool.luau +15 -15
  47. package/src/internal/Registry.luau +19 -19
  48. package/src/transport/Bridge.luau +17 -17
  49. package/src/transport/Client.luau +46 -46
  50. package/src/transport/Gate.luau +56 -64
  51. package/src/transport/Reader.luau +34 -34
  52. package/src/transport/Server.luau +89 -89
@@ -2,11 +2,11 @@
2
2
  --!native
3
3
  -- map and deltaMap codecs.
4
4
 
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
- local Varint = require (script.Parent.Parent.primitive.Varint)
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
+ local Varint = require(script.Parent.Parent.primitive.Varint)
10
10
 
11
11
  type ChannelState = Types.ChannelState
12
12
  type Codec<T> = Types.Codec<T>
@@ -21,11 +21,11 @@ local FLAG_DELTA = Shared.FLAG_DELTA
21
21
  local FLAG_FULL = Shared.FLAG_FULL
22
22
  local FLAG_UNCHANGED = Shared.FLAG_UNCHANGED
23
23
 
24
- -- Public -------------------------------------------------------------
24
+ -- Public --------------------------------------------------------------
25
25
 
26
26
  local Map = {}
27
27
 
28
- function Map.map (
28
+ function Map.map(
29
29
  keyCodec: Codec<any>,
30
30
  valueCodec: Codec<any>,
31
31
  maxCount: number?
@@ -43,48 +43,48 @@ function Map.map (
43
43
  if keySize and valSize and keyDWrite and valDWrite and keyDRead and valDRead then
44
44
  local entrySize = keySize + valSize
45
45
 
46
- return table.freeze ({
47
- write = function (ch: ChannelState, value: { [any]: any }): ()
46
+ return table.freeze({
47
+ write = function(ch: ChannelState, value: { [any]: any }): ()
48
48
  local count = 0
49
49
  for _ in value do
50
50
  count += 1
51
51
  end
52
52
 
53
- Varint.write (ch, count)
53
+ Varint.write(ch, count)
54
54
 
55
55
  if count > 0 then
56
56
  local totalBytes = count * entrySize
57
57
  local c = ch.cursor
58
58
  if c + totalBytes > ch.size then
59
- alloc (ch, totalBytes)
59
+ alloc(ch, totalBytes)
60
60
  end
61
61
 
62
62
  local b = ch.buff
63
63
  for k, v in value do
64
- keyDWrite (b, c, k)
65
- valDWrite (b, c + keySize, v)
64
+ keyDWrite(b, c, k)
65
+ valDWrite(b, c + keySize, v)
66
66
  c += entrySize
67
67
  end
68
68
  ch.cursor = c
69
69
  end
70
70
  end,
71
- read = function (
71
+ read = function(
72
72
  src: buffer,
73
73
  pos: number,
74
74
  _refs: { Instance }?
75
75
  ): ({ [any]: any }, number)
76
- local count, lenBytes = Varint.read (src, pos)
76
+ local count, lenBytes = Varint.read(src, pos)
77
77
 
78
78
  if maxCount and count > maxCount then
79
- error (`[Lync] Map count {count} exceeds max {maxCount}`)
79
+ error(`[Lync] Map count {count} exceeds max {maxCount}`)
80
80
  end
81
81
 
82
82
  local result = {}
83
83
  local c = pos + lenBytes
84
84
 
85
85
  for _ = 1, count do
86
- local k = keyDRead (src, c)
87
- local v = valDRead (src, c + keySize)
86
+ local k = keyDRead(src, c)
87
+ local v = valDRead(src, c + keySize)
88
88
  result[k] = v
89
89
  c += entrySize
90
90
  end
@@ -99,34 +99,34 @@ function Map.map (
99
99
  local readKey = keyCodec.read
100
100
  local readVal = valueCodec.read
101
101
 
102
- return table.freeze ({
103
- write = function (ch: ChannelState, value: { [any]: any }): ()
102
+ return table.freeze({
103
+ write = function(ch: ChannelState, value: { [any]: any }): ()
104
104
  local count = 0
105
105
  for _ in value do
106
106
  count += 1
107
107
  end
108
108
 
109
- Varint.write (ch, count)
109
+ Varint.write(ch, count)
110
110
 
111
111
  for k, v in value do
112
- writeKey (ch, k)
113
- writeVal (ch, v)
112
+ writeKey(ch, k)
113
+ writeVal(ch, v)
114
114
  end
115
115
  end,
116
- read = function (src: buffer, pos: number, refs: { Instance }?): ({ [any]: any }, number)
117
- local count, lenBytes = Varint.read (src, pos)
116
+ read = function(src: buffer, pos: number, refs: { Instance }?): ({ [any]: any }, number)
117
+ local count, lenBytes = Varint.read(src, pos)
118
118
 
119
119
  if maxCount and count > maxCount then
120
- error (`[Lync] Map count {count} exceeds max {maxCount}`)
120
+ error(`[Lync] Map count {count} exceeds max {maxCount}`)
121
121
  end
122
122
 
123
123
  local result = {}
124
124
  local absPos = pos + lenBytes
125
125
 
126
126
  for _ = 1, count do
127
- local k, kn = readKey (src, absPos, refs)
127
+ local k, kn = readKey(src, absPos, refs)
128
128
  absPos += kn
129
- local v, vn = readVal (src, absPos, refs)
129
+ local v, vn = readVal(src, absPos, refs)
130
130
  absPos += vn
131
131
  result[k] = v
132
132
  end
@@ -144,12 +144,12 @@ end
144
144
  FLAG_UNCHANGED: u8(2)
145
145
  FLAG_DELTA: u8(0) + varint(upsertN) + [key+value ...] + varint(removeN) + [key ...]
146
146
  ]]
147
- function Map.deltaMap (
147
+ function Map.deltaMap(
148
148
  keyCodec: Codec<any>,
149
149
  valueCodec: Codec<any>,
150
150
  maxCount: number?
151
151
  ): Codec<{ [any]: any }>
152
- local deltaId = Shared.allocDeltaId ()
152
+ local deltaId = Shared.allocDeltaId()
153
153
 
154
154
  local writeKey = keyCodec.write
155
155
  local writeVal = valueCodec.write
@@ -183,11 +183,11 @@ function Map.deltaMap (
183
183
  count: number,
184
184
  }
185
185
 
186
- return table.freeze ({
186
+ return table.freeze({
187
187
  _isDelta = true,
188
188
 
189
- write = function (ch: ChannelState, value: { [any]: any }): ()
190
- local scratch = acquireScratch ()
189
+ write = function(ch: ChannelState, value: { [any]: any }): ()
190
+ local scratch = acquireScratch()
191
191
 
192
192
  local entries = {} :: { EntryBounds }
193
193
  local keyLookup = {} :: { [string]: number }
@@ -197,10 +197,10 @@ function Map.deltaMap (
197
197
  for k, v in value do
198
198
  entryCount += 1
199
199
  local c = scratch.cursor
200
- alloc (scratch, entrySize :: number)
200
+ alloc(scratch, entrySize :: number)
201
201
  local b = scratch.buff
202
- keyDWrite (b, c, k)
203
- valDWrite (b, c + (keySize :: number), v)
202
+ keyDWrite(b, c, k)
203
+ valDWrite(b, c + (keySize :: number), v)
204
204
  scratch.cursor = c + (entrySize :: number)
205
205
 
206
206
  entries[entryCount] = {
@@ -210,16 +210,16 @@ function Map.deltaMap (
210
210
  valLen = valSize :: number,
211
211
  }
212
212
 
213
- local keyId = buffer.readstring (b, c, keySize :: number)
213
+ local keyId = buffer.readstring(b, c, keySize :: number)
214
214
  keyLookup[keyId] = entryCount
215
215
  end
216
216
  else
217
217
  for k, v in value do
218
218
  entryCount += 1
219
219
  local keyStart = scratch.cursor
220
- writeKey (scratch, k)
220
+ writeKey(scratch, k)
221
221
  local keyEnd = scratch.cursor
222
- writeVal (scratch, v)
222
+ writeVal(scratch, v)
223
223
  local valEnd = scratch.cursor
224
224
 
225
225
  entries[entryCount] = {
@@ -229,7 +229,7 @@ function Map.deltaMap (
229
229
  valLen = valEnd - keyEnd,
230
230
  }
231
231
 
232
- local keyId = buffer.readstring (scratch.buff, keyStart, keyEnd - keyStart)
232
+ local keyId = buffer.readstring(scratch.buff, keyStart, keyEnd - keyStart)
233
233
  keyLookup[keyId] = entryCount
234
234
  end
235
235
  end
@@ -238,14 +238,14 @@ function Map.deltaMap (
238
238
  local cache = ch.deltas[deltaId] :: DeltaMapCache?
239
239
 
240
240
  if not cache then
241
- alloc (ch, 1)
242
- buffer.writeu8 (ch.buff, ch.cursor, FLAG_FULL)
241
+ alloc(ch, 1)
242
+ buffer.writeu8(ch.buff, ch.cursor, FLAG_FULL)
243
243
  ch.cursor += 1
244
- Varint.write (ch, entryCount)
244
+ Varint.write(ch, entryCount)
245
245
 
246
246
  if scratchTotal > 0 then
247
- alloc (ch, scratchTotal)
248
- buffer.copy (ch.buff, ch.cursor, scratch.buff, 0, scratchTotal)
247
+ alloc(ch, scratchTotal)
248
+ buffer.copy(ch.buff, ch.cursor, scratch.buff, 0, scratchTotal)
249
249
  ch.cursor += scratchTotal
250
250
  end
251
251
  else
@@ -266,7 +266,7 @@ function Map.deltaMap (
266
266
  local oldE = cacheEntries[oldIdx]
267
267
  if
268
268
  newE.valLen ~= oldE.valLen
269
- or not rangeEqual (
269
+ or not rangeEqual(
270
270
  scratch.buff,
271
271
  newE.valOff,
272
272
  cacheRaw,
@@ -291,40 +291,40 @@ function Map.deltaMap (
291
291
  end
292
292
 
293
293
  if upsertN == 0 and removeN == 0 then
294
- alloc (ch, 1)
295
- buffer.writeu8 (ch.buff, ch.cursor, FLAG_UNCHANGED)
294
+ alloc(ch, 1)
295
+ buffer.writeu8(ch.buff, ch.cursor, FLAG_UNCHANGED)
296
296
  ch.cursor += 1
297
- releaseScratch ()
297
+ releaseScratch()
298
298
  return
299
299
  end
300
300
 
301
- alloc (ch, 1)
302
- buffer.writeu8 (ch.buff, ch.cursor, FLAG_DELTA)
301
+ alloc(ch, 1)
302
+ buffer.writeu8(ch.buff, ch.cursor, FLAG_DELTA)
303
303
  ch.cursor += 1
304
304
 
305
- Varint.write (ch, upsertN)
305
+ Varint.write(ch, upsertN)
306
306
  for i = 1, upsertN do
307
307
  local e = entries[upsertKeys[i]]
308
308
  local totalLen = e.keyLen + e.valLen
309
- alloc (ch, totalLen)
310
- buffer.copy (ch.buff, ch.cursor, scratch.buff, e.keyOff, totalLen)
309
+ alloc(ch, totalLen)
310
+ buffer.copy(ch.buff, ch.cursor, scratch.buff, e.keyOff, totalLen)
311
311
  ch.cursor += totalLen
312
312
  end
313
313
 
314
- Varint.write (ch, removeN)
314
+ Varint.write(ch, removeN)
315
315
  for i = 1, removeN do
316
316
  local keyId = removeKeyIds[i]
317
317
  local oldIdx = cacheLookup[keyId]
318
318
  local oldE = cacheEntries[oldIdx]
319
- alloc (ch, oldE.keyLen)
320
- buffer.copy (ch.buff, ch.cursor, cacheRaw, oldE.keyOff, oldE.keyLen)
319
+ alloc(ch, oldE.keyLen)
320
+ buffer.copy(ch.buff, ch.cursor, cacheRaw, oldE.keyOff, oldE.keyLen)
321
321
  ch.cursor += oldE.keyLen
322
322
  end
323
323
  end
324
324
 
325
- local rawBuf = buffer.create (scratchTotal)
325
+ local rawBuf = buffer.create(scratchTotal)
326
326
  if scratchTotal > 0 then
327
- buffer.copy (rawBuf, 0, scratch.buff, 0, scratchTotal)
327
+ buffer.copy(rawBuf, 0, scratch.buff, 0, scratchTotal)
328
328
  end
329
329
 
330
330
  ch.deltas[deltaId] = {
@@ -334,76 +334,76 @@ function Map.deltaMap (
334
334
  count = entryCount,
335
335
  }
336
336
 
337
- releaseScratch ()
337
+ releaseScratch()
338
338
  end,
339
339
 
340
- read = function (src: buffer, pos: number, refs: { Instance }?): ({ [any]: any }, number)
341
- local flag = buffer.readu8 (src, pos)
340
+ read = function(src: buffer, pos: number, refs: { Instance }?): ({ [any]: any }, number)
341
+ local flag = buffer.readu8(src, pos)
342
342
  local absPos = pos + 1
343
343
 
344
344
  if flag == FLAG_UNCHANGED then
345
- local cache = Baseline.getCache (deltaId)
346
- return if cache then table.clone (cache) else {}, 1
345
+ local cache = Baseline.getCache(deltaId)
346
+ return if cache then table.clone(cache) else {}, 1
347
347
  end
348
348
 
349
349
  if flag == FLAG_FULL then
350
- local count, lenBytes = Varint.read (src, absPos)
350
+ local count, lenBytes = Varint.read(src, absPos)
351
351
  absPos += lenBytes
352
352
 
353
353
  if maxCount and count > maxCount then
354
- error (`[Lync] Map count {count} exceeds max {maxCount}`)
354
+ error(`[Lync] Map count {count} exceeds max {maxCount}`)
355
355
  end
356
356
 
357
357
  local result = {}
358
358
 
359
359
  if keyDRead and valDRead and keySize and valSize then
360
360
  for _ = 1, count do
361
- local k = keyDRead (src, absPos)
362
- local v = valDRead (src, absPos + keySize)
361
+ local k = keyDRead(src, absPos)
362
+ local v = valDRead(src, absPos + keySize)
363
363
  result[k] = v
364
364
  absPos += entrySize :: number
365
365
  end
366
366
  else
367
367
  for _ = 1, count do
368
- local k, kn = readKey (src, absPos, refs)
368
+ local k, kn = readKey(src, absPos, refs)
369
369
  absPos += kn
370
- local v, vn = readVal (src, absPos, refs)
370
+ local v, vn = readVal(src, absPos, refs)
371
371
  absPos += vn
372
372
  result[k] = v
373
373
  end
374
374
  end
375
375
 
376
- Baseline.setCache (deltaId, result)
376
+ Baseline.setCache(deltaId, result)
377
377
  return result, absPos - pos
378
378
  end
379
379
 
380
- local cache = Baseline.getCache (deltaId) :: { [any]: any }?
381
- local result = if cache then table.clone (cache) else {}
380
+ local cache = Baseline.getCache(deltaId) :: { [any]: any }?
381
+ local result = if cache then table.clone(cache) else {}
382
382
 
383
- local upsertN, unBytes = Varint.read (src, absPos)
383
+ local upsertN, unBytes = Varint.read(src, absPos)
384
384
  absPos += unBytes
385
385
 
386
386
  for _ = 1, upsertN do
387
- local k, kn = readKey (src, absPos, refs)
387
+ local k, kn = readKey(src, absPos, refs)
388
388
  absPos += kn
389
- local v, vn = readVal (src, absPos, refs)
389
+ local v, vn = readVal(src, absPos, refs)
390
390
  absPos += vn
391
391
  result[k] = v
392
392
  end
393
393
 
394
- local removeN, rmBytes = Varint.read (src, absPos)
394
+ local removeN, rmBytes = Varint.read(src, absPos)
395
395
  absPos += rmBytes
396
396
 
397
397
  for _ = 1, removeN do
398
- local k, kn = readKey (src, absPos, refs)
398
+ local k, kn = readKey(src, absPos, refs)
399
399
  absPos += kn
400
400
  result[k] = nil
401
401
  end
402
402
 
403
- Baseline.setCache (deltaId, result)
403
+ Baseline.setCache(deltaId, result)
404
404
  return result, absPos - pos
405
405
  end,
406
406
  })
407
407
  end
408
408
 
409
- return table.freeze (Map)
409
+ return table.freeze(Map)
@@ -2,47 +2,47 @@
2
2
  --!native
3
3
  -- Optional codec. 1 byte flag, value only if present.
4
4
 
5
- local Channel = require (script.Parent.Parent.Parent.internal.Channel)
6
- local Types = require (script.Parent.Parent.Parent.Types)
5
+ local Channel = require(script.Parent.Parent.Parent.internal.Channel)
6
+ local Types = require(script.Parent.Parent.Parent.Types)
7
7
 
8
8
  type ChannelState = Types.ChannelState
9
9
  type Codec<T> = Types.Codec<T>
10
10
 
11
11
  local alloc = Channel.alloc
12
12
 
13
- -- Public -------------------------------------------------------------
13
+ -- Public --------------------------------------------------------------
14
14
 
15
15
  local Optional = {}
16
16
 
17
- function Optional.optional (inner: Codec<any>): Codec<any>
17
+ function Optional.optional(inner: Codec<any>): Codec<any>
18
18
  local innerWrite = inner.write
19
19
  local innerRead = inner.read
20
20
 
21
- return table.freeze ({
22
- write = function (ch: ChannelState, value: any): ()
21
+ return table.freeze({
22
+ write = function(ch: ChannelState, value: any): ()
23
23
  local c = ch.cursor
24
24
  if c + 1 > ch.size then
25
- alloc (ch, 1)
25
+ alloc(ch, 1)
26
26
  end
27
27
  if value == nil then
28
- buffer.writeu8 (ch.buff, c, 0)
28
+ buffer.writeu8(ch.buff, c, 0)
29
29
  ch.cursor = c + 1
30
30
  else
31
- buffer.writeu8 (ch.buff, c, 1)
31
+ buffer.writeu8(ch.buff, c, 1)
32
32
  ch.cursor = c + 1
33
- innerWrite (ch, value)
33
+ innerWrite(ch, value)
34
34
  end
35
35
  end,
36
- read = function (src: buffer, pos: number, refs: { Instance }?): (any, number)
37
- local flag = buffer.readu8 (src, pos)
36
+ read = function(src: buffer, pos: number, refs: { Instance }?): (any, number)
37
+ local flag = buffer.readu8(src, pos)
38
38
  if flag == 0 then
39
39
  return nil, 1
40
40
  end
41
41
 
42
- local value, n = innerRead (src, pos + 1, refs)
42
+ local value, n = innerRead(src, pos + 1, refs)
43
43
  return value, 1 + n
44
44
  end,
45
45
  })
46
46
  end
47
47
 
48
- return table.freeze (Optional)
48
+ return table.freeze(Optional)
@@ -2,14 +2,14 @@
2
2
  --!native
3
3
  -- Shared helpers for composite codecs: delta flags, scratch pool, struct field extraction, bool packing.
4
4
 
5
- local Channel = require (script.Parent.Parent.Parent.internal.Channel)
6
- local Types = require (script.Parent.Parent.Parent.Types)
5
+ local Channel = require(script.Parent.Parent.Parent.internal.Channel)
6
+ local Types = require(script.Parent.Parent.Parent.Types)
7
7
 
8
8
  type ChannelState = Types.ChannelState
9
9
 
10
10
  local alloc = Channel.alloc
11
11
 
12
- -- Constants ----------------------------------------------------------
12
+ -- Constants -----------------------------------------------------------
13
13
 
14
14
  local band = bit32.band
15
15
  local bor = bit32.bor
@@ -21,13 +21,13 @@ local FLAG_DELTA = 0
21
21
  local FLAG_FULL = 1
22
22
  local FLAG_UNCHANGED = 2
23
23
 
24
- -- State --------------------------------------------------------------
24
+ -- State ---------------------------------------------------------------
25
25
 
26
26
  local _nextDeltaId = 1
27
27
  local _scratchStack = {} :: { ChannelState }
28
28
  local _scratchDepth = 0
29
29
 
30
- -- Public -------------------------------------------------------------
30
+ -- Public --------------------------------------------------------------
31
31
 
32
32
  local Shared = {
33
33
  FLAG_DELTA = FLAG_DELTA,
@@ -35,38 +35,38 @@ local Shared = {
35
35
  FLAG_UNCHANGED = FLAG_UNCHANGED,
36
36
  }
37
37
 
38
- function Shared.allocDeltaId (): number
38
+ function Shared.allocDeltaId(): number
39
39
  local id = _nextDeltaId
40
40
  _nextDeltaId += 1
41
41
  return id
42
42
  end
43
43
 
44
- function Shared.acquireScratch (): ChannelState
44
+ function Shared.acquireScratch(): ChannelState
45
45
  _scratchDepth += 1
46
46
  local scratch = _scratchStack[_scratchDepth]
47
47
  if not scratch then
48
- scratch = Channel.create ()
48
+ scratch = Channel.create()
49
49
  _scratchStack[_scratchDepth] = scratch
50
50
  end
51
51
  scratch.cursor = 0
52
- table.clear (scratch.refs)
52
+ table.clear(scratch.refs)
53
53
  return scratch
54
54
  end
55
55
 
56
- function Shared.releaseScratch (): ()
56
+ function Shared.releaseScratch(): ()
57
57
  _scratchDepth -= 1
58
58
  end
59
59
 
60
- function Shared.rangeEqual (a: buffer, offA: number, b: buffer, offB: number, len: number): boolean
61
- local aligned = band (len, 0xFFFFFFFC)
60
+ function Shared.rangeEqual(a: buffer, offA: number, b: buffer, offB: number, len: number): boolean
61
+ local aligned = band(len, 0xFFFFFFFC)
62
62
  for i = 0, aligned - 4, 4 do
63
- if buffer.readu32 (a, offA + i) ~= buffer.readu32 (b, offB + i) then
63
+ if buffer.readu32(a, offA + i) ~= buffer.readu32(b, offB + i) then
64
64
  return false
65
65
  end
66
66
  end
67
67
 
68
68
  for i = aligned, len - 1 do
69
- if buffer.readu8 (a, offA + i) ~= buffer.readu8 (b, offB + i) then
69
+ if buffer.readu8(a, offA + i) ~= buffer.readu8(b, offB + i) then
70
70
  return false
71
71
  end
72
72
  end
@@ -74,80 +74,80 @@ function Shared.rangeEqual (a: buffer, offA: number, b: buffer, offB: number, le
74
74
  return true
75
75
  end
76
76
 
77
- function Shared.extractFields (schema: { [string]: any }): ({ string }, { any }, { string })
77
+ function Shared.extractFields(schema: { [string]: any }): ({ string }, { any }, { string })
78
78
  local dataKeys = {} :: { string }
79
79
  local dataCodecs = {} :: { any }
80
80
  local boolKeys = {} :: { string }
81
81
 
82
82
  for key, codec in schema do
83
83
  if codec._isBool then
84
- table.insert (boolKeys, key)
84
+ table.insert(boolKeys, key)
85
85
  else
86
- table.insert (dataKeys, key)
86
+ table.insert(dataKeys, key)
87
87
  end
88
88
  end
89
89
 
90
- table.sort (dataKeys)
91
- table.sort (boolKeys)
90
+ table.sort(dataKeys)
91
+ table.sort(boolKeys)
92
92
 
93
93
  if #dataKeys == 0 and #boolKeys == 0 then
94
- error ("[Lync] Struct requires at least one field")
94
+ error("[Lync] Struct requires at least one field")
95
95
  end
96
96
 
97
97
  for i = 1, #dataKeys do
98
98
  dataCodecs[i] = schema[dataKeys[i]]
99
99
  end
100
100
 
101
- table.freeze (dataKeys)
102
- table.freeze (dataCodecs)
103
- table.freeze (boolKeys)
101
+ table.freeze(dataKeys)
102
+ table.freeze(dataCodecs)
103
+ table.freeze(boolKeys)
104
104
 
105
105
  return dataKeys, dataCodecs, boolKeys
106
106
  end
107
107
 
108
- function Shared.packBools (ch: ChannelState, boolKeys: { string }, boolCount: number, value: any): ()
109
- local boolByteCount = ceil (boolCount / 8)
110
- alloc (ch, boolByteCount)
108
+ function Shared.packBools(ch: ChannelState, boolKeys: { string }, boolCount: number, value: any): ()
109
+ local boolByteCount = ceil(boolCount / 8)
110
+ alloc(ch, boolByteCount)
111
111
  local b = ch.buff
112
112
  local c = ch.cursor
113
113
 
114
114
  for byteIdx = 0, boolByteCount - 1 do
115
115
  local packed = 0
116
116
  local base = byteIdx * 8
117
- local limit = min (8, boolCount - base)
117
+ local limit = min(8, boolCount - base)
118
118
 
119
119
  for bit = 0, limit - 1 do
120
120
  if value[boolKeys[base + bit + 1]] then
121
- packed = bor (packed, lshift (1, bit))
121
+ packed = bor(packed, lshift(1, bit))
122
122
  end
123
123
  end
124
124
 
125
- buffer.writeu8 (b, c + byteIdx, packed)
125
+ buffer.writeu8(b, c + byteIdx, packed)
126
126
  end
127
127
 
128
128
  ch.cursor = c + boolByteCount
129
129
  end
130
130
 
131
- function Shared.unpackBools (
131
+ function Shared.unpackBools(
132
132
  src: buffer,
133
133
  pos: number,
134
134
  boolKeys: { string },
135
135
  boolCount: number,
136
136
  result: any
137
137
  ): number
138
- local boolByteCount = ceil (boolCount / 8)
138
+ local boolByteCount = ceil(boolCount / 8)
139
139
 
140
140
  for byteIdx = 0, boolByteCount - 1 do
141
- local byte = buffer.readu8 (src, pos + byteIdx)
141
+ local byte = buffer.readu8(src, pos + byteIdx)
142
142
  local base = byteIdx * 8
143
- local limit = min (8, boolCount - base)
143
+ local limit = min(8, boolCount - base)
144
144
 
145
145
  for bit = 0, limit - 1 do
146
- result[boolKeys[base + bit + 1]] = band (byte, lshift (1, bit)) ~= 0
146
+ result[boolKeys[base + bit + 1]] = band(byte, lshift(1, bit)) ~= 0
147
147
  end
148
148
  end
149
149
 
150
150
  return boolByteCount
151
151
  end
152
152
 
153
- return table.freeze (Shared)
153
+ return table.freeze(Shared)