bare-media 1.8.0 → 2.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.
@@ -1,440 +0,0 @@
1
- // This file is autogenerated by the hyperschema compiler
2
- // Schema Version: 2
3
- /* eslint-disable camelcase */
4
- /* eslint-disable quotes */
5
- /* eslint-disable space-before-function-paren */
6
-
7
- import { c } from 'hyperschema/runtime'
8
-
9
- const VERSION = 2
10
-
11
- // eslint-disable-next-line no-unused-vars
12
- let version = VERSION
13
-
14
- // @media/dimensions
15
- const encoding0 = {
16
- preencode(state, m) {
17
- c.uint.preencode(state, m.width)
18
- c.uint.preencode(state, m.height)
19
- },
20
- encode(state, m) {
21
- c.uint.encode(state, m.width)
22
- c.uint.encode(state, m.height)
23
- },
24
- decode(state) {
25
- const r0 = c.uint.decode(state)
26
- const r1 = c.uint.decode(state)
27
-
28
- return {
29
- width: r0,
30
- height: r1
31
- }
32
- }
33
- }
34
-
35
- // @media/metadata.dimensions
36
- const encoding1_1 = c.frame(encoding0)
37
-
38
- // @media/metadata
39
- const encoding1 = {
40
- preencode(state, m) {
41
- state.end++ // max flag is 4 so always one byte
42
-
43
- if (m.mimetype) c.string.preencode(state, m.mimetype)
44
- if (m.dimensions) encoding1_1.preencode(state, m.dimensions)
45
- if (m.duration) c.uint.preencode(state, m.duration)
46
- },
47
- encode(state, m) {
48
- const flags =
49
- (m.mimetype ? 1 : 0) | (m.dimensions ? 2 : 0) | (m.duration ? 4 : 0)
50
-
51
- c.uint.encode(state, flags)
52
-
53
- if (m.mimetype) c.string.encode(state, m.mimetype)
54
- if (m.dimensions) encoding1_1.encode(state, m.dimensions)
55
- if (m.duration) c.uint.encode(state, m.duration)
56
- },
57
- decode(state) {
58
- const flags = c.uint.decode(state)
59
-
60
- return {
61
- mimetype: (flags & 1) !== 0 ? c.string.decode(state) : null,
62
- dimensions: (flags & 2) !== 0 ? encoding1_1.decode(state) : null,
63
- duration: (flags & 4) !== 0 ? c.uint.decode(state) : 0
64
- }
65
- }
66
- }
67
-
68
- // @media/file.metadata
69
- const encoding2_0 = c.frame(encoding1)
70
-
71
- // @media/file
72
- const encoding2 = {
73
- preencode(state, m) {
74
- state.end++ // max flag is 4 so always one byte
75
-
76
- if (m.metadata) encoding2_0.preencode(state, m.metadata)
77
- if (m.inlined) c.string.preencode(state, m.inlined)
78
- if (m.buffer) c.buffer.preencode(state, m.buffer)
79
- },
80
- encode(state, m) {
81
- const flags =
82
- (m.metadata ? 1 : 0) | (m.inlined ? 2 : 0) | (m.buffer ? 4 : 0)
83
-
84
- c.uint.encode(state, flags)
85
-
86
- if (m.metadata) encoding2_0.encode(state, m.metadata)
87
- if (m.inlined) c.string.encode(state, m.inlined)
88
- if (m.buffer) c.buffer.encode(state, m.buffer)
89
- },
90
- decode(state) {
91
- const flags = c.uint.decode(state)
92
-
93
- return {
94
- metadata: (flags & 1) !== 0 ? encoding2_0.decode(state) : null,
95
- inlined: (flags & 2) !== 0 ? c.string.decode(state) : null,
96
- buffer: (flags & 4) !== 0 ? c.buffer.decode(state) : null
97
- }
98
- }
99
- }
100
-
101
- // @media/create-preview-request
102
- const encoding3 = {
103
- preencode(state, m) {
104
- const flags =
105
- (m.path ? 1 : 0) |
106
- (m.httpLink ? 2 : 0) |
107
- (m.buffer ? 4 : 0) |
108
- (m.mimetype ? 8 : 0) |
109
- (m.maxWidth ? 16 : 0) |
110
- (m.maxHeight ? 32 : 0) |
111
- (m.maxFrames ? 64 : 0) |
112
- (m.maxBytes ? 128 : 0) |
113
- (m.format ? 256 : 0) |
114
- (m.encoding ? 512 : 0)
115
-
116
- c.uint.preencode(state, flags)
117
-
118
- if (m.path) c.string.preencode(state, m.path)
119
- if (m.httpLink) c.string.preencode(state, m.httpLink)
120
- if (m.buffer) c.buffer.preencode(state, m.buffer)
121
- if (m.mimetype) c.string.preencode(state, m.mimetype)
122
- if (m.maxWidth) c.uint.preencode(state, m.maxWidth)
123
- if (m.maxHeight) c.uint.preencode(state, m.maxHeight)
124
- if (m.maxFrames) c.uint.preencode(state, m.maxFrames)
125
- if (m.maxBytes) c.uint.preencode(state, m.maxBytes)
126
- if (m.format) c.string.preencode(state, m.format)
127
- if (m.encoding) c.string.preencode(state, m.encoding)
128
- },
129
- encode(state, m) {
130
- const flags =
131
- (m.path ? 1 : 0) |
132
- (m.httpLink ? 2 : 0) |
133
- (m.buffer ? 4 : 0) |
134
- (m.mimetype ? 8 : 0) |
135
- (m.maxWidth ? 16 : 0) |
136
- (m.maxHeight ? 32 : 0) |
137
- (m.maxFrames ? 64 : 0) |
138
- (m.maxBytes ? 128 : 0) |
139
- (m.format ? 256 : 0) |
140
- (m.encoding ? 512 : 0)
141
-
142
- c.uint.encode(state, flags)
143
-
144
- if (m.path) c.string.encode(state, m.path)
145
- if (m.httpLink) c.string.encode(state, m.httpLink)
146
- if (m.buffer) c.buffer.encode(state, m.buffer)
147
- if (m.mimetype) c.string.encode(state, m.mimetype)
148
- if (m.maxWidth) c.uint.encode(state, m.maxWidth)
149
- if (m.maxHeight) c.uint.encode(state, m.maxHeight)
150
- if (m.maxFrames) c.uint.encode(state, m.maxFrames)
151
- if (m.maxBytes) c.uint.encode(state, m.maxBytes)
152
- if (m.format) c.string.encode(state, m.format)
153
- if (m.encoding) c.string.encode(state, m.encoding)
154
- },
155
- decode(state) {
156
- const flags = c.uint.decode(state)
157
-
158
- return {
159
- path: (flags & 1) !== 0 ? c.string.decode(state) : null,
160
- httpLink: (flags & 2) !== 0 ? c.string.decode(state) : null,
161
- buffer: (flags & 4) !== 0 ? c.buffer.decode(state) : null,
162
- mimetype: (flags & 8) !== 0 ? c.string.decode(state) : null,
163
- maxWidth: (flags & 16) !== 0 ? c.uint.decode(state) : 0,
164
- maxHeight: (flags & 32) !== 0 ? c.uint.decode(state) : 0,
165
- maxFrames: (flags & 64) !== 0 ? c.uint.decode(state) : 0,
166
- maxBytes: (flags & 128) !== 0 ? c.uint.decode(state) : 0,
167
- format: (flags & 256) !== 0 ? c.string.decode(state) : null,
168
- encoding: (flags & 512) !== 0 ? c.string.decode(state) : null
169
- }
170
- }
171
- }
172
-
173
- // @media/create-preview-response.metadata
174
- const encoding4_0 = encoding2_0
175
- // @media/create-preview-response.preview
176
- const encoding4_1 = c.frame(encoding2)
177
-
178
- // @media/create-preview-response
179
- const encoding4 = {
180
- preencode(state, m) {
181
- encoding4_0.preencode(state, m.metadata)
182
- encoding4_1.preencode(state, m.preview)
183
- },
184
- encode(state, m) {
185
- encoding4_0.encode(state, m.metadata)
186
- encoding4_1.encode(state, m.preview)
187
- },
188
- decode(state) {
189
- const r0 = encoding4_0.decode(state)
190
- const r1 = encoding4_1.decode(state)
191
-
192
- return {
193
- metadata: r0,
194
- preview: r1
195
- }
196
- }
197
- }
198
-
199
- // @media/decode-image-request
200
- const encoding5 = {
201
- preencode(state, m) {
202
- state.end++ // max flag is 8 so always one byte
203
-
204
- if (m.path) c.string.preencode(state, m.path)
205
- if (m.httpLink) c.string.preencode(state, m.httpLink)
206
- if (m.buffer) c.buffer.preencode(state, m.buffer)
207
- if (m.mimetype) c.string.preencode(state, m.mimetype)
208
- },
209
- encode(state, m) {
210
- const flags =
211
- (m.path ? 1 : 0) |
212
- (m.httpLink ? 2 : 0) |
213
- (m.buffer ? 4 : 0) |
214
- (m.mimetype ? 8 : 0)
215
-
216
- c.uint.encode(state, flags)
217
-
218
- if (m.path) c.string.encode(state, m.path)
219
- if (m.httpLink) c.string.encode(state, m.httpLink)
220
- if (m.buffer) c.buffer.encode(state, m.buffer)
221
- if (m.mimetype) c.string.encode(state, m.mimetype)
222
- },
223
- decode(state) {
224
- const flags = c.uint.decode(state)
225
-
226
- return {
227
- path: (flags & 1) !== 0 ? c.string.decode(state) : null,
228
- httpLink: (flags & 2) !== 0 ? c.string.decode(state) : null,
229
- buffer: (flags & 4) !== 0 ? c.buffer.decode(state) : null,
230
- mimetype: (flags & 8) !== 0 ? c.string.decode(state) : null
231
- }
232
- }
233
- }
234
-
235
- // @media/decode-image-response.metadata
236
- const encoding6_0 = encoding2_0
237
-
238
- // @media/decode-image-response
239
- const encoding6 = {
240
- preencode(state, m) {
241
- state.end++ // max flag is 2 so always one byte
242
-
243
- if (m.metadata) encoding6_0.preencode(state, m.metadata)
244
- if (m.data) c.buffer.preencode(state, m.data)
245
- },
246
- encode(state, m) {
247
- const flags = (m.metadata ? 1 : 0) | (m.data ? 2 : 0)
248
-
249
- c.uint.encode(state, flags)
250
-
251
- if (m.metadata) encoding6_0.encode(state, m.metadata)
252
- if (m.data) c.buffer.encode(state, m.data)
253
- },
254
- decode(state) {
255
- const flags = c.uint.decode(state)
256
-
257
- return {
258
- metadata: (flags & 1) !== 0 ? encoding6_0.decode(state) : null,
259
- data: (flags & 2) !== 0 ? c.buffer.decode(state) : null
260
- }
261
- }
262
- }
263
-
264
- // @media/crop-image-request
265
- const encoding7 = {
266
- preencode(state, m) {
267
- const flags =
268
- (version >= 2 && m.path ? 1 : 0) |
269
- (version >= 2 && m.httpLink ? 2 : 0) |
270
- (version >= 2 && m.buffer ? 4 : 0) |
271
- (version >= 2 && m.mimetype ? 8 : 0) |
272
- (version >= 2 && m.left ? 16 : 0) |
273
- (version >= 2 && m.top ? 32 : 0) |
274
- (version >= 2 && m.width ? 64 : 0) |
275
- (version >= 2 && m.height ? 128 : 0) |
276
- (version >= 2 && m.format ? 256 : 0)
277
-
278
- c.uint.preencode(state, flags)
279
-
280
- if (version >= 2 && m.path) c.string.preencode(state, m.path)
281
- if (version >= 2 && m.httpLink) c.string.preencode(state, m.httpLink)
282
- if (version >= 2 && m.buffer) c.buffer.preencode(state, m.buffer)
283
- if (version >= 2 && m.mimetype) c.string.preencode(state, m.mimetype)
284
- if (version >= 2 && m.left) c.uint.preencode(state, m.left)
285
- if (version >= 2 && m.top) c.uint.preencode(state, m.top)
286
- if (version >= 2 && m.width) c.uint.preencode(state, m.width)
287
- if (version >= 2 && m.height) c.uint.preencode(state, m.height)
288
- if (version >= 2 && m.format) c.string.preencode(state, m.format)
289
- },
290
- encode(state, m) {
291
- const flags =
292
- (version >= 2 && m.path ? 1 : 0) |
293
- (version >= 2 && m.httpLink ? 2 : 0) |
294
- (version >= 2 && m.buffer ? 4 : 0) |
295
- (version >= 2 && m.mimetype ? 8 : 0) |
296
- (version >= 2 && m.left ? 16 : 0) |
297
- (version >= 2 && m.top ? 32 : 0) |
298
- (version >= 2 && m.width ? 64 : 0) |
299
- (version >= 2 && m.height ? 128 : 0) |
300
- (version >= 2 && m.format ? 256 : 0)
301
-
302
- c.uint.encode(state, flags)
303
-
304
- if (version >= 2 && m.path) c.string.encode(state, m.path)
305
- if (version >= 2 && m.httpLink) c.string.encode(state, m.httpLink)
306
- if (version >= 2 && m.buffer) c.buffer.encode(state, m.buffer)
307
- if (version >= 2 && m.mimetype) c.string.encode(state, m.mimetype)
308
- if (version >= 2 && m.left) c.uint.encode(state, m.left)
309
- if (version >= 2 && m.top) c.uint.encode(state, m.top)
310
- if (version >= 2 && m.width) c.uint.encode(state, m.width)
311
- if (version >= 2 && m.height) c.uint.encode(state, m.height)
312
- if (version >= 2 && m.format) c.string.encode(state, m.format)
313
- },
314
- decode(state) {
315
- const flags = c.uint.decode(state)
316
-
317
- return {
318
- path: version >= 2 && (flags & 1) !== 0 ? c.string.decode(state) : null,
319
- httpLink:
320
- version >= 2 && (flags & 2) !== 0 ? c.string.decode(state) : null,
321
- buffer: version >= 2 && (flags & 4) !== 0 ? c.buffer.decode(state) : null,
322
- mimetype:
323
- version >= 2 && (flags & 8) !== 0 ? c.string.decode(state) : null,
324
- left: version >= 2 && (flags & 16) !== 0 ? c.uint.decode(state) : 0,
325
- top: version >= 2 && (flags & 32) !== 0 ? c.uint.decode(state) : 0,
326
- width: version >= 2 && (flags & 64) !== 0 ? c.uint.decode(state) : 0,
327
- height: version >= 2 && (flags & 128) !== 0 ? c.uint.decode(state) : 0,
328
- format:
329
- version >= 2 && (flags & 256) !== 0 ? c.string.decode(state) : null
330
- }
331
- }
332
- }
333
-
334
- // @media/crop-image-response.metadata
335
- const encoding8_0 = encoding2_0
336
-
337
- // @media/crop-image-response
338
- const encoding8 = {
339
- preencode(state, m) {
340
- state.end++ // max flag is 2 so always one byte
341
-
342
- if (version >= 2 && m.metadata) encoding8_0.preencode(state, m.metadata)
343
- if (version >= 2 && m.data) c.buffer.preencode(state, m.data)
344
- },
345
- encode(state, m) {
346
- const flags =
347
- (version >= 2 && m.metadata ? 1 : 0) | (version >= 2 && m.data ? 2 : 0)
348
-
349
- c.uint.encode(state, flags)
350
-
351
- if (version >= 2 && m.metadata) encoding8_0.encode(state, m.metadata)
352
- if (version >= 2 && m.data) c.buffer.encode(state, m.data)
353
- },
354
- decode(state) {
355
- const flags = c.uint.decode(state)
356
-
357
- return {
358
- metadata:
359
- version >= 2 && (flags & 1) !== 0 ? encoding8_0.decode(state) : null,
360
- data: version >= 2 && (flags & 2) !== 0 ? c.buffer.decode(state) : null
361
- }
362
- }
363
- }
364
-
365
- function setVersion(v) {
366
- version = v
367
- }
368
-
369
- function encode(name, value, v = VERSION) {
370
- version = v
371
- return c.encode(getEncoding(name), value)
372
- }
373
-
374
- function decode(name, buffer, v = VERSION) {
375
- version = v
376
- return c.decode(getEncoding(name), buffer)
377
- }
378
-
379
- function getEnum(name) {
380
- switch (name) {
381
- default:
382
- throw new Error('Enum not found ' + name)
383
- }
384
- }
385
-
386
- function getEncoding(name) {
387
- switch (name) {
388
- case '@media/dimensions':
389
- return encoding0
390
- case '@media/metadata':
391
- return encoding1
392
- case '@media/file':
393
- return encoding2
394
- case '@media/create-preview-request':
395
- return encoding3
396
- case '@media/create-preview-response':
397
- return encoding4
398
- case '@media/decode-image-request':
399
- return encoding5
400
- case '@media/decode-image-response':
401
- return encoding6
402
- case '@media/crop-image-request':
403
- return encoding7
404
- case '@media/crop-image-response':
405
- return encoding8
406
- default:
407
- throw new Error('Encoder not found ' + name)
408
- }
409
- }
410
-
411
- function getStruct(name, v = VERSION) {
412
- const enc = getEncoding(name)
413
- return {
414
- preencode(state, m) {
415
- version = v
416
- enc.preencode(state, m)
417
- },
418
- encode(state, m) {
419
- version = v
420
- enc.encode(state, m)
421
- },
422
- decode(state) {
423
- version = v
424
- return enc.decode(state)
425
- }
426
- }
427
- }
428
-
429
- const resolveStruct = getStruct // compat
430
-
431
- export {
432
- resolveStruct,
433
- getStruct,
434
- getEnum,
435
- getEncoding,
436
- encode,
437
- decode,
438
- setVersion,
439
- version
440
- }