@data-vegle/serial 0.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/LICENSE +21 -0
- package/README.md +87 -0
- package/flamework.build +11 -0
- package/out/index.d.ts +3 -0
- package/out/init.luau +5 -0
- package/out/lib/BufferReader.d.ts +19 -0
- package/out/lib/BufferReader.luau +97 -0
- package/out/lib/BufferWriter.d.ts +22 -0
- package/out/lib/BufferWriter.luau +122 -0
- package/out/lib/Codec.d.ts +7 -0
- package/out/lib/Codec.luau +2 -0
- package/out/lib/CodecCompiler.d.ts +5 -0
- package/out/lib/CodecCompiler.luau +164 -0
- package/out/lib/CollectionCodecs.d.ts +10 -0
- package/out/lib/CollectionCodecs.luau +256 -0
- package/out/lib/PrimitiveCodecs.d.ts +8 -0
- package/out/lib/PrimitiveCodecs.luau +110 -0
- package/out/lib/RobloxCodecs.d.ts +29 -0
- package/out/lib/RobloxCodecs.luau +506 -0
- package/out/lib/Serializer.d.ts +14 -0
- package/out/lib/Serializer.luau +45 -0
- package/out/lib/SerializerMetadata.d.ts +63 -0
- package/out/lib/SerializerMetadata.luau +2 -0
- package/package.json +45 -0
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
|
|
2
|
+
local a=1
|
|
3
|
+
local b=2
|
|
4
|
+
local c=4
|
|
5
|
+
local d=1
|
|
6
|
+
local e=2
|
|
7
|
+
local f=4
|
|
8
|
+
local g=8
|
|
9
|
+
local h=16
|
|
10
|
+
local i=32
|
|
11
|
+
local j
|
|
12
|
+
local function createEnumCodecByName(k)
|
|
13
|
+
local l=Enum
|
|
14
|
+
local m=l[k]
|
|
15
|
+
if m==nil then
|
|
16
|
+
error(string.format([[[Serialization] an enum schema referenced an unknown enum: %s]], tostring(k)))
|
|
17
|
+
end
|
|
18
|
+
return j(m)
|
|
19
|
+
end
|
|
20
|
+
function j(k)
|
|
21
|
+
local l=k:GetEnumItems()
|
|
22
|
+
local m={}
|
|
23
|
+
for n,o in l do
|
|
24
|
+
local p=o.Value
|
|
25
|
+
m[p]=o
|
|
26
|
+
end
|
|
27
|
+
return{
|
|
28
|
+
write=function(p,q,r)
|
|
29
|
+
q:writeVarUint(r.Value)
|
|
30
|
+
end,
|
|
31
|
+
read=function(p,q)
|
|
32
|
+
local r=q:readVarUint()
|
|
33
|
+
local s=m[r]
|
|
34
|
+
if s==nil then
|
|
35
|
+
error(string.format([[[Serialization] an enum read a value that does not exist: %s]], tostring(r)))
|
|
36
|
+
end
|
|
37
|
+
return s
|
|
38
|
+
end,
|
|
39
|
+
}
|
|
40
|
+
end
|
|
41
|
+
local k={
|
|
42
|
+
write=function(k,l,m)
|
|
43
|
+
l:writeF32(m.X)
|
|
44
|
+
l:writeF32(m.Y)
|
|
45
|
+
l:writeF32(m.Z)
|
|
46
|
+
end,
|
|
47
|
+
read=function(k,l)
|
|
48
|
+
local m=l:readF32()
|
|
49
|
+
local n=l:readF32()
|
|
50
|
+
local o=l:readF32()
|
|
51
|
+
return Vector3.new(m,n,o)
|
|
52
|
+
end,
|
|
53
|
+
}
|
|
54
|
+
local l={
|
|
55
|
+
write=function(l,m,n)
|
|
56
|
+
m:writeF32(n.X)
|
|
57
|
+
m:writeF32(n.Y)
|
|
58
|
+
end,
|
|
59
|
+
read=function(l,m)
|
|
60
|
+
local n=m:readF32()
|
|
61
|
+
local o=m:readF32()
|
|
62
|
+
return Vector2.new(n,o)
|
|
63
|
+
end,
|
|
64
|
+
}
|
|
65
|
+
local m={
|
|
66
|
+
write=function(m,n,o)
|
|
67
|
+
n:writeI16(o.X)
|
|
68
|
+
n:writeI16(o.Y)
|
|
69
|
+
n:writeI16(o.Z)
|
|
70
|
+
end,
|
|
71
|
+
read=function(m,n)
|
|
72
|
+
local o=n:readI16()
|
|
73
|
+
local p=n:readI16()
|
|
74
|
+
local q=n:readI16()
|
|
75
|
+
return Vector3int16.new(o,p,q)
|
|
76
|
+
end,
|
|
77
|
+
}
|
|
78
|
+
local n={
|
|
79
|
+
write=function(n,o,p)
|
|
80
|
+
o:writeI16(p.X)
|
|
81
|
+
o:writeI16(p.Y)
|
|
82
|
+
end,
|
|
83
|
+
read=function(n,o)
|
|
84
|
+
local p=o:readI16()
|
|
85
|
+
local q=o:readI16()
|
|
86
|
+
return Vector2int16.new(p,q)
|
|
87
|
+
end,
|
|
88
|
+
}
|
|
89
|
+
local o={
|
|
90
|
+
write=function(o,p,q)
|
|
91
|
+
local r=q.Position
|
|
92
|
+
local s,t,u=q:ToOrientation()
|
|
93
|
+
p:writeF32(r.X)
|
|
94
|
+
p:writeF32(r.Y)
|
|
95
|
+
p:writeF32(r.Z)
|
|
96
|
+
p:writeF32(s)
|
|
97
|
+
p:writeF32(t)
|
|
98
|
+
p:writeF32(u)
|
|
99
|
+
end,
|
|
100
|
+
read=function(o,p)
|
|
101
|
+
local q=p:readF32()
|
|
102
|
+
local r=p:readF32()
|
|
103
|
+
local s=p:readF32()
|
|
104
|
+
local t=p:readF32()
|
|
105
|
+
local u=p:readF32()
|
|
106
|
+
local v=p:readF32()
|
|
107
|
+
local w=CFrame.fromOrientation(t,u,v)
|
|
108
|
+
local x=Vector3.new(q,r,s)
|
|
109
|
+
return w+x
|
|
110
|
+
end,
|
|
111
|
+
}
|
|
112
|
+
local p={
|
|
113
|
+
write=function(p,q,r)
|
|
114
|
+
q:writeF32(r.R)
|
|
115
|
+
q:writeF32(r.G)
|
|
116
|
+
q:writeF32(r.B)
|
|
117
|
+
end,
|
|
118
|
+
read=function(p,q)
|
|
119
|
+
local r=q:readF32()
|
|
120
|
+
local s=q:readF32()
|
|
121
|
+
local t=q:readF32()
|
|
122
|
+
return Color3.new(r,s,t)
|
|
123
|
+
end,
|
|
124
|
+
}
|
|
125
|
+
local q={
|
|
126
|
+
write=function(q,r,s)
|
|
127
|
+
r:writeVarUint(s.Number)
|
|
128
|
+
end,
|
|
129
|
+
read=function(q,r)
|
|
130
|
+
local s=r:readVarUint()
|
|
131
|
+
return BrickColor.new(s)
|
|
132
|
+
end,
|
|
133
|
+
}
|
|
134
|
+
local r={
|
|
135
|
+
write=function(r,s,t)
|
|
136
|
+
s:writeF32(t.Scale)
|
|
137
|
+
s:writeI32(t.Offset)
|
|
138
|
+
end,
|
|
139
|
+
read=function(r,s)
|
|
140
|
+
local t=s:readF32()
|
|
141
|
+
local u=s:readI32()
|
|
142
|
+
return UDim.new(t,u)
|
|
143
|
+
end,
|
|
144
|
+
}
|
|
145
|
+
local s={
|
|
146
|
+
write=function(s,t,u)
|
|
147
|
+
t:writeF32(u.X.Scale)
|
|
148
|
+
t:writeI32(u.X.Offset)
|
|
149
|
+
t:writeF32(u.Y.Scale)
|
|
150
|
+
t:writeI32(u.Y.Offset)
|
|
151
|
+
end,
|
|
152
|
+
read=function(s,t)
|
|
153
|
+
local u=t:readF32()
|
|
154
|
+
local v=t:readI32()
|
|
155
|
+
local w=t:readF32()
|
|
156
|
+
local x=t:readI32()
|
|
157
|
+
return UDim2.new(u,v,w,x)
|
|
158
|
+
end,
|
|
159
|
+
}
|
|
160
|
+
local t={
|
|
161
|
+
write=function(t,u,v)
|
|
162
|
+
u:writeF32(v.Min.X)
|
|
163
|
+
u:writeF32(v.Min.Y)
|
|
164
|
+
u:writeF32(v.Max.X)
|
|
165
|
+
u:writeF32(v.Max.Y)
|
|
166
|
+
end,
|
|
167
|
+
read=function(t,u)
|
|
168
|
+
local v=u:readF32()
|
|
169
|
+
local w=u:readF32()
|
|
170
|
+
local x=u:readF32()
|
|
171
|
+
local y=u:readF32()
|
|
172
|
+
local z=Vector2.new(v,w)
|
|
173
|
+
local A=Vector2.new(x,y)
|
|
174
|
+
return Rect.new(z,A)
|
|
175
|
+
end,
|
|
176
|
+
}
|
|
177
|
+
local u={
|
|
178
|
+
write=function(u,v,w)
|
|
179
|
+
local x=w.Origin
|
|
180
|
+
local y=w.Direction
|
|
181
|
+
v:writeF32(x.X)
|
|
182
|
+
v:writeF32(x.Y)
|
|
183
|
+
v:writeF32(x.Z)
|
|
184
|
+
v:writeF32(y.X)
|
|
185
|
+
v:writeF32(y.Y)
|
|
186
|
+
v:writeF32(y.Z)
|
|
187
|
+
end,
|
|
188
|
+
read=function(u,v)
|
|
189
|
+
local w=v:readF32()
|
|
190
|
+
local x=v:readF32()
|
|
191
|
+
local y=v:readF32()
|
|
192
|
+
local z=v:readF32()
|
|
193
|
+
local A=v:readF32()
|
|
194
|
+
local B=v:readF32()
|
|
195
|
+
local C=Vector3.new(w,x,y)
|
|
196
|
+
local D=Vector3.new(z,A,B)
|
|
197
|
+
return Ray.new(C,D)
|
|
198
|
+
end,
|
|
199
|
+
}
|
|
200
|
+
local v={
|
|
201
|
+
write=function(v,w,x)
|
|
202
|
+
local y=x.Size
|
|
203
|
+
local z=y/2
|
|
204
|
+
local A=x.CFrame.Position
|
|
205
|
+
local B=A-z
|
|
206
|
+
local C=A+z
|
|
207
|
+
w:writeF32(B.X)
|
|
208
|
+
w:writeF32(B.Y)
|
|
209
|
+
w:writeF32(B.Z)
|
|
210
|
+
w:writeF32(C.X)
|
|
211
|
+
w:writeF32(C.Y)
|
|
212
|
+
w:writeF32(C.Z)
|
|
213
|
+
end,
|
|
214
|
+
read=function(v,w)
|
|
215
|
+
local x=w:readF32()
|
|
216
|
+
local y=w:readF32()
|
|
217
|
+
local z=w:readF32()
|
|
218
|
+
local A=w:readF32()
|
|
219
|
+
local B=w:readF32()
|
|
220
|
+
local C=w:readF32()
|
|
221
|
+
local D=Vector3.new(x,y,z)
|
|
222
|
+
local E=Vector3.new(A,B,C)
|
|
223
|
+
return Region3.new(D,E)
|
|
224
|
+
end,
|
|
225
|
+
}
|
|
226
|
+
local w={
|
|
227
|
+
write=function(w,x,y)
|
|
228
|
+
x:writeI16(y.Min.X)
|
|
229
|
+
x:writeI16(y.Min.Y)
|
|
230
|
+
x:writeI16(y.Min.Z)
|
|
231
|
+
x:writeI16(y.Max.X)
|
|
232
|
+
x:writeI16(y.Max.Y)
|
|
233
|
+
x:writeI16(y.Max.Z)
|
|
234
|
+
end,
|
|
235
|
+
read=function(w,x)
|
|
236
|
+
local y=x:readI16()
|
|
237
|
+
local z=x:readI16()
|
|
238
|
+
local A=x:readI16()
|
|
239
|
+
local B=x:readI16()
|
|
240
|
+
local C=x:readI16()
|
|
241
|
+
local D=x:readI16()
|
|
242
|
+
local E=Vector3int16.new(y,z,A)
|
|
243
|
+
local F=Vector3int16.new(B,C,D)
|
|
244
|
+
return Region3int16.new(E,F)
|
|
245
|
+
end,
|
|
246
|
+
}
|
|
247
|
+
local x={
|
|
248
|
+
write=function(x,y,z)
|
|
249
|
+
y:writeF32(z.Min)
|
|
250
|
+
y:writeF32(z.Max)
|
|
251
|
+
end,
|
|
252
|
+
read=function(x,y)
|
|
253
|
+
local z=y:readF32()
|
|
254
|
+
local A=y:readF32()
|
|
255
|
+
return NumberRange.new(z,A)
|
|
256
|
+
end,
|
|
257
|
+
}
|
|
258
|
+
local y={
|
|
259
|
+
write=function(y,z,A)
|
|
260
|
+
local B=A.Keypoints
|
|
261
|
+
local C=#B
|
|
262
|
+
z:writeVarUint(C)
|
|
263
|
+
for D,E in B do
|
|
264
|
+
z:writeF32(E.Time)
|
|
265
|
+
z:writeF32(E.Value)
|
|
266
|
+
z:writeF32(E.Envelope)
|
|
267
|
+
end
|
|
268
|
+
end,
|
|
269
|
+
read=function(y,z)
|
|
270
|
+
local A=z:readVarUint()
|
|
271
|
+
local B={}
|
|
272
|
+
do
|
|
273
|
+
local C=0
|
|
274
|
+
local D=false
|
|
275
|
+
while true do
|
|
276
|
+
if D then
|
|
277
|
+
C=C+1
|
|
278
|
+
else
|
|
279
|
+
D=true
|
|
280
|
+
end
|
|
281
|
+
if not(C<A)then
|
|
282
|
+
break
|
|
283
|
+
end
|
|
284
|
+
local E=z:readF32()
|
|
285
|
+
local F=z:readF32()
|
|
286
|
+
local G=z:readF32()
|
|
287
|
+
local H=NumberSequenceKeypoint.new(E,F,G)
|
|
288
|
+
table.insert(B,H)
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
return NumberSequence.new(B)
|
|
292
|
+
end,
|
|
293
|
+
}
|
|
294
|
+
local z={
|
|
295
|
+
write=function(z,A,B)
|
|
296
|
+
local C=B.Keypoints
|
|
297
|
+
local D=#C
|
|
298
|
+
A:writeVarUint(D)
|
|
299
|
+
for E,F in C do
|
|
300
|
+
local G=F.Value
|
|
301
|
+
A:writeF32(F.Time)
|
|
302
|
+
A:writeF32(G.R)
|
|
303
|
+
A:writeF32(G.G)
|
|
304
|
+
A:writeF32(G.B)
|
|
305
|
+
end
|
|
306
|
+
end,
|
|
307
|
+
read=function(z,A)
|
|
308
|
+
local B=A:readVarUint()
|
|
309
|
+
local C={}
|
|
310
|
+
do
|
|
311
|
+
local D=0
|
|
312
|
+
local E=false
|
|
313
|
+
while true do
|
|
314
|
+
if E then
|
|
315
|
+
D=D+1
|
|
316
|
+
else
|
|
317
|
+
E=true
|
|
318
|
+
end
|
|
319
|
+
if not(D<B)then
|
|
320
|
+
break
|
|
321
|
+
end
|
|
322
|
+
local F=A:readF32()
|
|
323
|
+
local G=A:readF32()
|
|
324
|
+
local H=A:readF32()
|
|
325
|
+
local I=A:readF32()
|
|
326
|
+
local J=Color3.new(G,H,I)
|
|
327
|
+
local K=ColorSequenceKeypoint.new(F,J)
|
|
328
|
+
table.insert(C,K)
|
|
329
|
+
end
|
|
330
|
+
end
|
|
331
|
+
return ColorSequence.new(C)
|
|
332
|
+
end,
|
|
333
|
+
}
|
|
334
|
+
local A={
|
|
335
|
+
write=function(A,B,C)
|
|
336
|
+
B:writeF32(C.Density)
|
|
337
|
+
B:writeF32(C.Friction)
|
|
338
|
+
B:writeF32(C.Elasticity)
|
|
339
|
+
B:writeF32(C.FrictionWeight)
|
|
340
|
+
B:writeF32(C.ElasticityWeight)
|
|
341
|
+
end,
|
|
342
|
+
read=function(A,B)
|
|
343
|
+
local C=B:readF32()
|
|
344
|
+
local D=B:readF32()
|
|
345
|
+
local E=B:readF32()
|
|
346
|
+
local F=B:readF32()
|
|
347
|
+
local G=B:readF32()
|
|
348
|
+
return PhysicalProperties.new(C,D,E,F,G)
|
|
349
|
+
end,
|
|
350
|
+
}
|
|
351
|
+
local B={
|
|
352
|
+
write=function(B,C,D)
|
|
353
|
+
C:writeF64(D.UnixTimestampMillis)
|
|
354
|
+
end,
|
|
355
|
+
read=function(B,C)
|
|
356
|
+
local D=C:readF64()
|
|
357
|
+
return DateTime.fromUnixTimestampMillis(D)
|
|
358
|
+
end,
|
|
359
|
+
}
|
|
360
|
+
local C=j(Enum.FontWeight)
|
|
361
|
+
local D=j(Enum.FontStyle)
|
|
362
|
+
local E=j(Enum.EasingStyle)
|
|
363
|
+
local F=j(Enum.EasingDirection)
|
|
364
|
+
local G={
|
|
365
|
+
write=function(G,H,I)
|
|
366
|
+
H:writeString(I.Family)
|
|
367
|
+
C:write(H,I.Weight)
|
|
368
|
+
D:write(H,I.Style)
|
|
369
|
+
end,
|
|
370
|
+
read=function(G,H)
|
|
371
|
+
local I=H:readString()
|
|
372
|
+
local J=C:read(H)
|
|
373
|
+
local K=D:read(H)
|
|
374
|
+
return Font.new(I,J,K)
|
|
375
|
+
end,
|
|
376
|
+
}
|
|
377
|
+
local H={
|
|
378
|
+
write=function(H,I,J)
|
|
379
|
+
I:writeF32(J.Time)
|
|
380
|
+
E:write(I,J.EasingStyle)
|
|
381
|
+
F:write(I,J.EasingDirection)
|
|
382
|
+
I:writeI32(J.RepeatCount)
|
|
383
|
+
I:writeBool(J.Reverses)
|
|
384
|
+
I:writeF32(J.DelayTime)
|
|
385
|
+
end,
|
|
386
|
+
read=function(H,I)
|
|
387
|
+
local J=I:readF32()
|
|
388
|
+
local K=E:read(I)
|
|
389
|
+
local L=F:read(I)
|
|
390
|
+
local M=I:readI32()
|
|
391
|
+
local N=I:readBool()
|
|
392
|
+
local O=I:readF32()
|
|
393
|
+
return TweenInfo.new(J,K,L,M,N,O)
|
|
394
|
+
end,
|
|
395
|
+
}
|
|
396
|
+
local I={
|
|
397
|
+
write=function(I,J,K)
|
|
398
|
+
local L=0
|
|
399
|
+
if K.X then
|
|
400
|
+
L=L+a
|
|
401
|
+
end
|
|
402
|
+
if K.Y then
|
|
403
|
+
L=L+b
|
|
404
|
+
end
|
|
405
|
+
if K.Z then
|
|
406
|
+
L=L+c
|
|
407
|
+
end
|
|
408
|
+
J:writeU8(L)
|
|
409
|
+
end,
|
|
410
|
+
read=function(I,J)
|
|
411
|
+
local K=J:readU8()
|
|
412
|
+
local L={}
|
|
413
|
+
if bit32.band(K,a)~=0 then
|
|
414
|
+
local M=Enum.Axis.X
|
|
415
|
+
table.insert(L,M)
|
|
416
|
+
end
|
|
417
|
+
if bit32.band(K,b)~=0 then
|
|
418
|
+
local M=Enum.Axis.Y
|
|
419
|
+
table.insert(L,M)
|
|
420
|
+
end
|
|
421
|
+
if bit32.band(K,c)~=0 then
|
|
422
|
+
local M=Enum.Axis.Z
|
|
423
|
+
table.insert(L,M)
|
|
424
|
+
end
|
|
425
|
+
return Axes.new(unpack(L))
|
|
426
|
+
end,
|
|
427
|
+
}
|
|
428
|
+
local J={
|
|
429
|
+
write=function(J,K,L)
|
|
430
|
+
local M=0
|
|
431
|
+
if L.Top then
|
|
432
|
+
M=M+d
|
|
433
|
+
end
|
|
434
|
+
if L.Bottom then
|
|
435
|
+
M=M+e
|
|
436
|
+
end
|
|
437
|
+
if L.Left then
|
|
438
|
+
M=M+f
|
|
439
|
+
end
|
|
440
|
+
if L.Right then
|
|
441
|
+
M=M+g
|
|
442
|
+
end
|
|
443
|
+
if L.Back then
|
|
444
|
+
M=M+h
|
|
445
|
+
end
|
|
446
|
+
if L.Front then
|
|
447
|
+
M=M+i
|
|
448
|
+
end
|
|
449
|
+
K:writeU8(M)
|
|
450
|
+
end,
|
|
451
|
+
read=function(J,K)
|
|
452
|
+
local L=K:readU8()
|
|
453
|
+
local M={}
|
|
454
|
+
if bit32.band(L,d)~=0 then
|
|
455
|
+
local N=Enum.NormalId.Top
|
|
456
|
+
table.insert(M,N)
|
|
457
|
+
end
|
|
458
|
+
if bit32.band(L,e)~=0 then
|
|
459
|
+
local N=Enum.NormalId.Bottom
|
|
460
|
+
table.insert(M,N)
|
|
461
|
+
end
|
|
462
|
+
if bit32.band(L,f)~=0 then
|
|
463
|
+
local N=Enum.NormalId.Left
|
|
464
|
+
table.insert(M,N)
|
|
465
|
+
end
|
|
466
|
+
if bit32.band(L,g)~=0 then
|
|
467
|
+
local N=Enum.NormalId.Right
|
|
468
|
+
table.insert(M,N)
|
|
469
|
+
end
|
|
470
|
+
if bit32.band(L,h)~=0 then
|
|
471
|
+
local N=Enum.NormalId.Back
|
|
472
|
+
table.insert(M,N)
|
|
473
|
+
end
|
|
474
|
+
if bit32.band(L,i)~=0 then
|
|
475
|
+
local N=Enum.NormalId.Front
|
|
476
|
+
table.insert(M,N)
|
|
477
|
+
end
|
|
478
|
+
return Faces.new(unpack(M))
|
|
479
|
+
end,
|
|
480
|
+
}
|
|
481
|
+
return{
|
|
482
|
+
createEnumCodecByName=createEnumCodecByName,
|
|
483
|
+
createEnumCodec=j,
|
|
484
|
+
vector3Codec=k,
|
|
485
|
+
vector2Codec=l,
|
|
486
|
+
vector3int16Codec=m,
|
|
487
|
+
vector2int16Codec=n,
|
|
488
|
+
cframeCodec=o,
|
|
489
|
+
color3Codec=p,
|
|
490
|
+
brickColorCodec=q,
|
|
491
|
+
udimCodec=r,
|
|
492
|
+
udim2Codec=s,
|
|
493
|
+
rectCodec=t,
|
|
494
|
+
rayCodec=u,
|
|
495
|
+
region3Codec=v,
|
|
496
|
+
region3int16Codec=w,
|
|
497
|
+
numberRangeCodec=x,
|
|
498
|
+
numberSequenceCodec=y,
|
|
499
|
+
colorSequenceCodec=z,
|
|
500
|
+
physicalPropertiesCodec=A,
|
|
501
|
+
dateTimeCodec=B,
|
|
502
|
+
fontCodec=G,
|
|
503
|
+
tweenInfoCodec=H,
|
|
504
|
+
axesCodec=I,
|
|
505
|
+
facesCodec=J,
|
|
506
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Modding } from "@flamework/core";
|
|
2
|
+
import type { SerializerMetadata } from "./SerializerMetadata";
|
|
3
|
+
export type SerializedData = [buffer, Array<defined>];
|
|
4
|
+
/**
|
|
5
|
+
* @metadata macro
|
|
6
|
+
*/
|
|
7
|
+
export declare class Serializer<T> {
|
|
8
|
+
private readonly meta?;
|
|
9
|
+
private readonly schema;
|
|
10
|
+
private readonly codec;
|
|
11
|
+
constructor(meta?: Modding.Many<SerializerMetadata<T>> | undefined);
|
|
12
|
+
serialize(value: T): SerializedData;
|
|
13
|
+
deserialize(data: SerializedData): T;
|
|
14
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
|
|
2
|
+
local a=_G[script]
|
|
3
|
+
local b=a.import(script,script.Parent,"BufferReader").BufferReader
|
|
4
|
+
local c=a.import(script,script.Parent,"BufferWriter").BufferWriter
|
|
5
|
+
local d=a.import(script,script.Parent,"CodecCompiler").compileCodec
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
local e
|
|
12
|
+
do
|
|
13
|
+
e=setmetatable({},{
|
|
14
|
+
__tostring=function()
|
|
15
|
+
return"Serializer"
|
|
16
|
+
end,
|
|
17
|
+
})
|
|
18
|
+
e.__index=e
|
|
19
|
+
function e.new(...)
|
|
20
|
+
local f=setmetatable({},e)
|
|
21
|
+
return f:constructor(...)or f
|
|
22
|
+
end
|
|
23
|
+
function e.constructor(f,g)
|
|
24
|
+
f.meta=g
|
|
25
|
+
if g==nil then
|
|
26
|
+
error"[Serialization] createSerializer was called without a generated schema"
|
|
27
|
+
end
|
|
28
|
+
f.schema=g
|
|
29
|
+
f.codec=d(f.schema)
|
|
30
|
+
end
|
|
31
|
+
function e.serialize(f,g)
|
|
32
|
+
local h=c.new()
|
|
33
|
+
f.codec:write(h,g)
|
|
34
|
+
local i=h:getBuffer()
|
|
35
|
+
local j=h:getBlobs()
|
|
36
|
+
return{i,j}
|
|
37
|
+
end
|
|
38
|
+
function e.deserialize(f,g)
|
|
39
|
+
local h=b.new(g[1],g[2])
|
|
40
|
+
return f.codec:read(h)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
return{
|
|
44
|
+
Serializer=e,
|
|
45
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
type Mask<V, T> = T extends object ? V & Reconstruct<T> : V;
|
|
2
|
+
type IsLiteral<T> = T extends undefined ? true : T extends string ? Mask<string, T> extends T ? false : true : T extends number ? Mask<number, T> extends T ? false : true : T extends boolean ? true : false;
|
|
3
|
+
type HasNominal<T> = T extends T ? (T extends `_nominal_${string}` ? true : never) : never;
|
|
4
|
+
type IsUnion<T, U = T> = true extends (T extends T ? (U extends T ? never : true) : never) ? true : false;
|
|
5
|
+
type IsExactlyBoolean<T> = [T] extends [boolean] ? ([boolean] extends [T] ? true : false) : false;
|
|
6
|
+
type IsLiteralUnion<T> = [boolean, NonNullable<T>] extends [NonNullable<T>, boolean] ? false : (T extends T ? (T extends undefined ? true : IsLiteral<T> extends true ? true : false) : never) extends true ? true : false;
|
|
7
|
+
type NonUnionKeys<T> = {
|
|
8
|
+
[K in keyof T]: true extends IsUnion<T[K]> ? never : K;
|
|
9
|
+
}[keyof T];
|
|
10
|
+
type LiteralKeys<T> = {
|
|
11
|
+
[K in keyof T]: true extends IsLiteral<T[K]> ? K : never;
|
|
12
|
+
}[keyof T];
|
|
13
|
+
type DiscriminatorKeys<T> = NonUnionKeys<T> & LiteralKeys<T>;
|
|
14
|
+
type SharedDiscriminators<T> = UnionToIntersection<T extends T ? [DiscriminatorKeys<T>] : never>[never];
|
|
15
|
+
type UniqueDiscriminators<T, D extends keyof T, U extends T = T> = D extends D ? (T extends T ? (T[D] extends Exclude<U, T>[D] ? unknown : D) : never) extends D ? D : never : never;
|
|
16
|
+
type FindDiscriminator<T> = UniqueDiscriminators<T, SharedDiscriminators<T>>;
|
|
17
|
+
type IsDiscriminableUnion<T> = true extends IsUnion<T> ? (FindDiscriminator<T> extends never ? false : true) : false;
|
|
18
|
+
type EnumName<T> = [T] extends [EnumItem] ? ExtractKeys<Enums, T["EnumType"]> : never;
|
|
19
|
+
interface RobloxDataTypes {
|
|
20
|
+
readonly vector3: Vector3;
|
|
21
|
+
readonly vector2: Vector2;
|
|
22
|
+
readonly vector3int16: Vector3int16;
|
|
23
|
+
readonly vector2int16: Vector2int16;
|
|
24
|
+
readonly cframe: CFrame;
|
|
25
|
+
readonly color3: Color3;
|
|
26
|
+
readonly udim: UDim;
|
|
27
|
+
readonly udim2: UDim2;
|
|
28
|
+
readonly rect: Rect;
|
|
29
|
+
readonly ray: Ray;
|
|
30
|
+
readonly region3: Region3;
|
|
31
|
+
readonly region3int16: Region3int16;
|
|
32
|
+
readonly numberrange: NumberRange;
|
|
33
|
+
readonly numbersequence: NumberSequence;
|
|
34
|
+
readonly colorsequence: ColorSequence;
|
|
35
|
+
readonly physicalproperties: PhysicalProperties;
|
|
36
|
+
readonly datetime: DateTime;
|
|
37
|
+
readonly tweeninfo: TweenInfo;
|
|
38
|
+
readonly font: Font;
|
|
39
|
+
readonly axes: Axes;
|
|
40
|
+
readonly faces: Faces;
|
|
41
|
+
}
|
|
42
|
+
type LiteralMode<T> = true extends IsUnion<T> ? (undefined extends T ? 1 : 0) : -1;
|
|
43
|
+
type TupleMetadata<T extends ReadonlyArray<unknown>> = [
|
|
44
|
+
"tuple",
|
|
45
|
+
{
|
|
46
|
+
[K in keyof T]: SerializerMetadata<T[K]>;
|
|
47
|
+
}
|
|
48
|
+
];
|
|
49
|
+
type ArrayMetadata<T extends ReadonlyArray<unknown>> = [T] extends [
|
|
50
|
+
{
|
|
51
|
+
length: number;
|
|
52
|
+
}
|
|
53
|
+
] ? TupleMetadata<T> : ["list", SerializerMetadata<T[number]>];
|
|
54
|
+
type VariantMetadata<T> = FindDiscriminator<T> extends infer D ? T extends T ? [T[D & keyof T], SerializerMetadata<Omit<T, D & keyof T>>] : never : never;
|
|
55
|
+
type FieldMetadata<T> = {
|
|
56
|
+
[K in keyof T]-?: [K, SerializerMetadata<T[K]>];
|
|
57
|
+
}[keyof T];
|
|
58
|
+
export type SerializerMetadata<T> = IsExactlyBoolean<T> extends true ? ["bool"] : IsLiteralUnion<T> extends true ? ["literal", Array<NonNullable<T>>, LiteralMode<T>] : unknown extends T ? ["optional", ["blob"]] : undefined extends T ? ["optional", SerializerMetadata<NonNullable<T>>] : [T] extends [number] ? ["f64"] : [T] extends [string] ? ["string"] : [T] extends [buffer] ? ["buffer"] : [T] extends [BrickColor] ? ["brickcolor"] : [T] extends [RobloxDataTypes[keyof RobloxDataTypes]] ? [ExtractKeys<RobloxDataTypes, T>] : [T] extends [ReadonlySet<infer V>] ? ["set", SerializerMetadata<V>] : [T] extends [ReadonlyMap<infer K, infer V>] ? ["map", SerializerMetadata<K>, SerializerMetadata<V>] : [T] extends [ReadonlyArray<unknown>] ? ArrayMetadata<T> : [T] extends [EnumItem] ? ["enum", EnumName<T>] : IsDiscriminableUnion<T> extends true ? [
|
|
59
|
+
"union",
|
|
60
|
+
FindDiscriminator<T>,
|
|
61
|
+
Array<VariantMetadata<T>>
|
|
62
|
+
] : true extends IsUnion<T> ? ["blob"] : true extends HasNominal<keyof T> ? ["blob"] : T extends object ? ["object", Array<FieldMetadata<T>>] : ["blob"];
|
|
63
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@data-vegle/serial",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Serialize roblox-ts types into buffers.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "out/init.luau",
|
|
7
|
+
"types": "out/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"out",
|
|
10
|
+
"flamework.build",
|
|
11
|
+
"!**/*.tsbuildinfo"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rbxtsc && npm run minify",
|
|
15
|
+
"minify": "node scripts/minify.js",
|
|
16
|
+
"watch": "rbxtsc --type=package -w",
|
|
17
|
+
"clean": "rimraf out include",
|
|
18
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
19
|
+
"format:check": "prettier --check \"src/**/*.ts\"",
|
|
20
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"roblox",
|
|
24
|
+
"roblox-ts",
|
|
25
|
+
"flamework",
|
|
26
|
+
"buffer",
|
|
27
|
+
"serialization"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@flamework/core": "^1.3.2"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@rbxts/compiler-types": "3.0.0-types.0",
|
|
37
|
+
"@rbxts/types": "^1.0.943",
|
|
38
|
+
"darklua-wasm": "^0.1.0",
|
|
39
|
+
"prettier": "^3.3.3",
|
|
40
|
+
"rbxts-transformer-flamework": "^1.3.2",
|
|
41
|
+
"rimraf": "^6.0.1",
|
|
42
|
+
"roblox-ts": "^3.0.0",
|
|
43
|
+
"typescript": "=5.5.3"
|
|
44
|
+
}
|
|
45
|
+
}
|