@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.
@@ -0,0 +1,256 @@
1
+
2
+ local function optional(a)
3
+ return{
4
+ write=function(b,c,d)
5
+ local e=d~=nil
6
+ c:writeBool(e)
7
+ if e then
8
+ a:write(c,d)
9
+ end
10
+ end,
11
+ read=function(b,c)
12
+ local d=c:readBool()
13
+ if not d then
14
+ return nil
15
+ end
16
+ return a:read(c)
17
+ end,
18
+ }
19
+ end
20
+ local function list(a)
21
+ return{
22
+ write=function(b,c,d)
23
+ local e=d
24
+ local f=#e
25
+ c:writeVarUint(f)
26
+ for g,h in e do
27
+ a:write(c,h)
28
+ end
29
+ end,
30
+ read=function(b,c)
31
+ local d=c:readVarUint()
32
+ local e={}
33
+ do
34
+ local f=0
35
+ local g=false
36
+ while true do
37
+ if g then
38
+ f=f+1
39
+ else
40
+ g=true
41
+ end
42
+ if not(f<d)then
43
+ break
44
+ end
45
+ local h=a:read(c)
46
+ table.insert(e,h)
47
+ end
48
+ end
49
+ return e
50
+ end,
51
+ }
52
+ end
53
+ local function tuple(a)
54
+ local b=#a
55
+ return{
56
+ write=function(c,d,e)
57
+ local f=e
58
+ do
59
+ local g=0
60
+ local h=false
61
+ while true do
62
+ if h then
63
+ g=g+1
64
+ else
65
+ h=true
66
+ end
67
+ if not(g<b)then
68
+ break
69
+ end
70
+ local i=a[g+1]
71
+ i:write(d,f[g+1])
72
+ end
73
+ end
74
+ end,
75
+ read=function(c,d)
76
+ local e={}
77
+ do
78
+ local f=0
79
+ local g=false
80
+ while true do
81
+ if g then
82
+ f=f+1
83
+ else
84
+ g=true
85
+ end
86
+ if not(f<b)then
87
+ break
88
+ end
89
+ local h=a[f+1]
90
+ e[f+1]=h:read(d)
91
+ end
92
+ end
93
+ return e
94
+ end,
95
+ }
96
+ end
97
+ local function set(a)
98
+ return{
99
+ write=function(b,c,d)
100
+ local e=d
101
+
102
+ local f=0
103
+ for g in e do
104
+ f=f+1
105
+ end
106
+
107
+ local h=f
108
+ c:writeVarUint(h)
109
+ for i in e do
110
+ a:write(c,i)
111
+ end
112
+ end,
113
+ read=function(b,c)
114
+ local d=c:readVarUint()
115
+ local e={}
116
+ do
117
+ local f=0
118
+ local g=false
119
+ while true do
120
+ if g then
121
+ f=f+1
122
+ else
123
+ g=true
124
+ end
125
+ if not(f<d)then
126
+ break
127
+ end
128
+ local h=a:read(c)
129
+ e[h]=true
130
+ end
131
+ end
132
+ return e
133
+ end,
134
+ }
135
+ end
136
+ local function map(a,b)
137
+ return{
138
+ write=function(c,d,e)
139
+ local f=e
140
+
141
+ local g=0
142
+ for h in f do
143
+ g=g+1
144
+ end
145
+
146
+ local i=g
147
+ d:writeVarUint(i)
148
+ for j,k in f do
149
+ a:write(d,j)
150
+ b:write(d,k)
151
+ end
152
+ end,
153
+ read=function(c,d)
154
+ local e=d:readVarUint()
155
+ local f={}
156
+ do
157
+ local g=0
158
+ local h=false
159
+ while true do
160
+ if h then
161
+ g=g+1
162
+ else
163
+ h=true
164
+ end
165
+ if not(g<e)then
166
+ break
167
+ end
168
+ local i=a:read(d)
169
+ local j=b:read(d)
170
+ f[i]=j
171
+ end
172
+ end
173
+ return f
174
+ end,
175
+ }
176
+ end
177
+ local function object(a)
178
+ return{
179
+ write=function(b,c,d)
180
+ local e=d
181
+ for f,g in a do
182
+ local h=g[1]
183
+ local i=g[2]
184
+ i:write(c,e[h])
185
+ end
186
+ end,
187
+ read=function(b,c)
188
+ local d={}
189
+ for e,f in a do
190
+ local g=f[1]
191
+ local h=f[2]
192
+ d[g]=h:read(c)
193
+ end
194
+ return d
195
+ end,
196
+ }
197
+ end
198
+ local function variant(a,b)
199
+ local c={}
200
+ local d=#b
201
+ do
202
+ local e=0
203
+ local f=false
204
+ while true do
205
+ if f then
206
+ e=e+1
207
+ else
208
+ f=true
209
+ end
210
+ if not(e<d)then
211
+ break
212
+ end
213
+ local g=b[e+1]
214
+ local h=g[1]
215
+ local i=e
216
+ c[h]=i
217
+ end
218
+ end
219
+ return{
220
+ write=function(e,f,g)
221
+ local h=g
222
+ local i=h[a]
223
+ local j=c[i]
224
+ if j==nil then
225
+ local k=tostring(i)
226
+ error(string.format('[Serialization] a union received an unknown "%s" tag: %s', tostring(a), tostring(k)))
227
+ end
228
+ f:writeVarUint(j)
229
+ local k=b[j+1]
230
+ local l=k[2]
231
+ l:write(f,g)
232
+ end,
233
+ read=function(e,f)
234
+ local g=f:readVarUint()
235
+ local h=b[g+1]
236
+ if h==nil then
237
+ error(string.format('[Serialization] a union read an unknown tag index: %s', tostring(g)))
238
+ end
239
+ local i=h
240
+ local j=i[1]
241
+ local k=i[2]
242
+ local l=k:read(f)
243
+ l[a]=j
244
+ return l
245
+ end,
246
+ }
247
+ end
248
+ return{
249
+ optional=optional,
250
+ list=list,
251
+ tuple=tuple,
252
+ set=set,
253
+ map=map,
254
+ object=object,
255
+ variant=variant,
256
+ }
@@ -0,0 +1,8 @@
1
+ import type { AnyCodec, Codec } from "./Codec";
2
+ export declare const boolCodec: Codec<boolean>;
3
+ export declare const f64Codec: Codec<number>;
4
+ export declare const stringCodec: Codec<string>;
5
+ export declare const bufferCodec: Codec<buffer>;
6
+ export declare const blobCodec: Codec<defined>;
7
+ export declare function literal(value: defined): AnyCodec;
8
+ export declare function literalUnion(values: ReadonlyArray<defined>, allowsUndefined: boolean): AnyCodec;
@@ -0,0 +1,110 @@
1
+
2
+ local a={
3
+ write=function(a,b,c)
4
+ b:writeBool(c)
5
+ end,
6
+ read=function(a,b)
7
+ return b:readBool()
8
+ end,
9
+ }
10
+ local b={
11
+ write=function(b,c,d)
12
+ c:writeF64(d)
13
+ end,
14
+ read=function(b,c)
15
+ return c:readF64()
16
+ end,
17
+ }
18
+ local c={
19
+ write=function(c,d,e)
20
+ d:writeString(e)
21
+ end,
22
+ read=function(c,d)
23
+ return d:readString()
24
+ end,
25
+ }
26
+ local d={
27
+ write=function(d,e,f)
28
+ e:writeBuffer(f)
29
+ end,
30
+ read=function(d,e)
31
+ return e:readBuffer()
32
+ end,
33
+ }
34
+ local e={
35
+ write=function(e,f,g)
36
+ f:writeBlob(g)
37
+ end,
38
+ read=function(e,f)
39
+ return f:readBlob()
40
+ end,
41
+ }
42
+ local function literal(f)
43
+ return{
44
+ write=function(g)
45
+ return nil
46
+ end,
47
+ read=function(g)
48
+ return f
49
+ end,
50
+ }
51
+ end
52
+ local function literalUnion(f,g)
53
+ local h={}
54
+ local i=#f
55
+ do
56
+ local j=0
57
+ local k=false
58
+ while true do
59
+ if k then
60
+ j=j+1
61
+ else
62
+ k=true
63
+ end
64
+ if not(j<i)then
65
+ break
66
+ end
67
+ local l=f[j+1]
68
+ local m=j
69
+ h[l]=m
70
+ end
71
+ end
72
+ return{
73
+ write=function(j,k,l)
74
+ if l==nil then
75
+ if not g then
76
+ error"[Serialization] a literal union received undefined but does not allow it"
77
+ end
78
+ k:writeVarUint(i)
79
+ return nil
80
+ end
81
+ local m=l
82
+ local n=h[m]
83
+ if n==nil then
84
+ local o=tostring(l)
85
+ error(string.format([[[Serialization] a literal union received a value outside of its set: %s]], tostring(o)))
86
+ end
87
+ k:writeVarUint(n)
88
+ end,
89
+ read=function(j,k)
90
+ local l=k:readVarUint()
91
+ if l==i then
92
+ return nil
93
+ end
94
+ local m=f[l+1]
95
+ if m==nil then
96
+ error(string.format([[[Serialization] a literal union read an index outside of its set: %s]], tostring(l)))
97
+ end
98
+ return m
99
+ end,
100
+ }
101
+ end
102
+ return{
103
+ literal=literal,
104
+ literalUnion=literalUnion,
105
+ boolCodec=a,
106
+ f64Codec=b,
107
+ stringCodec=c,
108
+ bufferCodec=d,
109
+ blobCodec=e,
110
+ }
@@ -0,0 +1,29 @@
1
+ import type { Codec } from "./Codec";
2
+ interface EnumSource {
3
+ GetEnumItems(): Array<EnumItem>;
4
+ }
5
+ export declare function createEnumCodecByName(name: string): Codec<EnumItem>;
6
+ export declare function createEnumCodec(source: EnumSource): Codec<EnumItem>;
7
+ export declare const vector3Codec: Codec<Vector3>;
8
+ export declare const vector2Codec: Codec<Vector2>;
9
+ export declare const vector3int16Codec: Codec<Vector3int16>;
10
+ export declare const vector2int16Codec: Codec<Vector2int16>;
11
+ export declare const cframeCodec: Codec<CFrame>;
12
+ export declare const color3Codec: Codec<Color3>;
13
+ export declare const brickColorCodec: Codec<BrickColor>;
14
+ export declare const udimCodec: Codec<UDim>;
15
+ export declare const udim2Codec: Codec<UDim2>;
16
+ export declare const rectCodec: Codec<Rect>;
17
+ export declare const rayCodec: Codec<Ray>;
18
+ export declare const region3Codec: Codec<Region3>;
19
+ export declare const region3int16Codec: Codec<Region3int16>;
20
+ export declare const numberRangeCodec: Codec<NumberRange>;
21
+ export declare const numberSequenceCodec: Codec<NumberSequence>;
22
+ export declare const colorSequenceCodec: Codec<ColorSequence>;
23
+ export declare const physicalPropertiesCodec: Codec<PhysicalProperties>;
24
+ export declare const dateTimeCodec: Codec<DateTime>;
25
+ export declare const fontCodec: Codec<Font>;
26
+ export declare const tweenInfoCodec: Codec<TweenInfo>;
27
+ export declare const axesCodec: Codec<Axes>;
28
+ export declare const facesCodec: Codec<Faces>;
29
+ export {};