1// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
2
3package data
4
5import (
6 "fmt"
7 "io"
8 "math"
9 "sort"
10
11 cid "github.com/ipfs/go-cid"
12 cbg "github.com/whyrusleeping/cbor-gen"
13 xerrors "golang.org/x/xerrors"
14)
15
16var _ = xerrors.Errorf
17var _ = cid.Undef
18var _ = math.E
19var _ = sort.Sort
20
21func (t *GenericRecord) MarshalCBOR(w io.Writer) error {
22 if t == nil {
23 _, err := w.Write(cbg.CborNull)
24 return err
25 }
26
27 cw := cbg.NewCborWriter(w)
28
29 if _, err := cw.Write([]byte{161}); err != nil {
30 return err
31 }
32
33 // t.Type (string) (string)
34 if len("$type") > 1000000 {
35 return xerrors.Errorf("Value in field \"$type\" was too long")
36 }
37
38 if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil {
39 return err
40 }
41 if _, err := cw.WriteString(string("$type")); err != nil {
42 return err
43 }
44
45 if len(t.Type) > 1000000 {
46 return xerrors.Errorf("Value in field t.Type was too long")
47 }
48
49 if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Type))); err != nil {
50 return err
51 }
52 if _, err := cw.WriteString(string(t.Type)); err != nil {
53 return err
54 }
55 return nil
56}
57
58func (t *GenericRecord) UnmarshalCBOR(r io.Reader) (err error) {
59 *t = GenericRecord{}
60
61 cr := cbg.NewCborReader(r)
62
63 maj, extra, err := cr.ReadHeader()
64 if err != nil {
65 return err
66 }
67 defer func() {
68 if err == io.EOF {
69 err = io.ErrUnexpectedEOF
70 }
71 }()
72
73 if maj != cbg.MajMap {
74 return fmt.Errorf("cbor input should be of type map")
75 }
76
77 if extra > cbg.MaxLength {
78 return fmt.Errorf("GenericRecord: map struct too large (%d)", extra)
79 }
80
81 n := extra
82
83 nameBuf := make([]byte, 5)
84 for i := uint64(0); i < n; i++ {
85 nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000)
86 if err != nil {
87 return err
88 }
89
90 if !ok {
91 // Field doesn't exist on this type, so ignore it
92 if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil {
93 return err
94 }
95 continue
96 }
97
98 switch string(nameBuf[:nameLen]) {
99 // t.Type (string) (string)
100 case "$type":
101
102 {
103 sval, err := cbg.ReadStringWithMax(cr, 1000000)
104 if err != nil {
105 return err
106 }
107
108 t.Type = string(sval)
109 }
110
111 default:
112 // Field doesn't exist on this type, so ignore it
113 if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil {
114 return err
115 }
116 }
117 }
118
119 return nil
120}
121func (t *LegacyBlobSchema) MarshalCBOR(w io.Writer) error {
122 if t == nil {
123 _, err := w.Write(cbg.CborNull)
124 return err
125 }
126
127 cw := cbg.NewCborWriter(w)
128
129 if _, err := cw.Write([]byte{162}); err != nil {
130 return err
131 }
132
133 // t.Cid (string) (string)
134 if len("cid") > 1000000 {
135 return xerrors.Errorf("Value in field \"cid\" was too long")
136 }
137
138 if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("cid"))); err != nil {
139 return err
140 }
141 if _, err := cw.WriteString(string("cid")); err != nil {
142 return err
143 }
144
145 if len(t.Cid) > 1000000 {
146 return xerrors.Errorf("Value in field t.Cid was too long")
147 }
148
149 if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Cid))); err != nil {
150 return err
151 }
152 if _, err := cw.WriteString(string(t.Cid)); err != nil {
153 return err
154 }
155
156 // t.MimeType (string) (string)
157 if len("mimeType") > 1000000 {
158 return xerrors.Errorf("Value in field \"mimeType\" was too long")
159 }
160
161 if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("mimeType"))); err != nil {
162 return err
163 }
164 if _, err := cw.WriteString(string("mimeType")); err != nil {
165 return err
166 }
167
168 if len(t.MimeType) > 1000000 {
169 return xerrors.Errorf("Value in field t.MimeType was too long")
170 }
171
172 if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.MimeType))); err != nil {
173 return err
174 }
175 if _, err := cw.WriteString(string(t.MimeType)); err != nil {
176 return err
177 }
178 return nil
179}
180
181func (t *LegacyBlobSchema) UnmarshalCBOR(r io.Reader) (err error) {
182 *t = LegacyBlobSchema{}
183
184 cr := cbg.NewCborReader(r)
185
186 maj, extra, err := cr.ReadHeader()
187 if err != nil {
188 return err
189 }
190 defer func() {
191 if err == io.EOF {
192 err = io.ErrUnexpectedEOF
193 }
194 }()
195
196 if maj != cbg.MajMap {
197 return fmt.Errorf("cbor input should be of type map")
198 }
199
200 if extra > cbg.MaxLength {
201 return fmt.Errorf("LegacyBlobSchema: map struct too large (%d)", extra)
202 }
203
204 n := extra
205
206 nameBuf := make([]byte, 8)
207 for i := uint64(0); i < n; i++ {
208 nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000)
209 if err != nil {
210 return err
211 }
212
213 if !ok {
214 // Field doesn't exist on this type, so ignore it
215 if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil {
216 return err
217 }
218 continue
219 }
220
221 switch string(nameBuf[:nameLen]) {
222 // t.Cid (string) (string)
223 case "cid":
224
225 {
226 sval, err := cbg.ReadStringWithMax(cr, 1000000)
227 if err != nil {
228 return err
229 }
230
231 t.Cid = string(sval)
232 }
233 // t.MimeType (string) (string)
234 case "mimeType":
235
236 {
237 sval, err := cbg.ReadStringWithMax(cr, 1000000)
238 if err != nil {
239 return err
240 }
241
242 t.MimeType = string(sval)
243 }
244
245 default:
246 // Field doesn't exist on this type, so ignore it
247 if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil {
248 return err
249 }
250 }
251 }
252
253 return nil
254}
255func (t *BlobSchema) MarshalCBOR(w io.Writer) error {
256 if t == nil {
257 _, err := w.Write(cbg.CborNull)
258 return err
259 }
260
261 cw := cbg.NewCborWriter(w)
262
263 if _, err := cw.Write([]byte{164}); err != nil {
264 return err
265 }
266
267 // t.Ref (data.CIDLink) (struct)
268 if len("ref") > 1000000 {
269 return xerrors.Errorf("Value in field \"ref\" was too long")
270 }
271
272 if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("ref"))); err != nil {
273 return err
274 }
275 if _, err := cw.WriteString(string("ref")); err != nil {
276 return err
277 }
278
279 if err := t.Ref.MarshalCBOR(cw); err != nil {
280 return err
281 }
282
283 // t.Size (int64) (int64)
284 if len("size") > 1000000 {
285 return xerrors.Errorf("Value in field \"size\" was too long")
286 }
287
288 if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("size"))); err != nil {
289 return err
290 }
291 if _, err := cw.WriteString(string("size")); err != nil {
292 return err
293 }
294
295 if t.Size >= 0 {
296 if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Size)); err != nil {
297 return err
298 }
299 } else {
300 if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Size-1)); err != nil {
301 return err
302 }
303 }
304
305 // t.LexiconTypeID (string) (string)
306 if len("$type") > 1000000 {
307 return xerrors.Errorf("Value in field \"$type\" was too long")
308 }
309
310 if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil {
311 return err
312 }
313 if _, err := cw.WriteString(string("$type")); err != nil {
314 return err
315 }
316
317 if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("blob"))); err != nil {
318 return err
319 }
320 if _, err := cw.WriteString(string("blob")); err != nil {
321 return err
322 }
323
324 // t.MimeType (string) (string)
325 if len("mimeType") > 1000000 {
326 return xerrors.Errorf("Value in field \"mimeType\" was too long")
327 }
328
329 if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("mimeType"))); err != nil {
330 return err
331 }
332 if _, err := cw.WriteString(string("mimeType")); err != nil {
333 return err
334 }
335
336 if len(t.MimeType) > 1000000 {
337 return xerrors.Errorf("Value in field t.MimeType was too long")
338 }
339
340 if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.MimeType))); err != nil {
341 return err
342 }
343 if _, err := cw.WriteString(string(t.MimeType)); err != nil {
344 return err
345 }
346 return nil
347}
348
349func (t *BlobSchema) UnmarshalCBOR(r io.Reader) (err error) {
350 *t = BlobSchema{}
351
352 cr := cbg.NewCborReader(r)
353
354 maj, extra, err := cr.ReadHeader()
355 if err != nil {
356 return err
357 }
358 defer func() {
359 if err == io.EOF {
360 err = io.ErrUnexpectedEOF
361 }
362 }()
363
364 if maj != cbg.MajMap {
365 return fmt.Errorf("cbor input should be of type map")
366 }
367
368 if extra > cbg.MaxLength {
369 return fmt.Errorf("BlobSchema: map struct too large (%d)", extra)
370 }
371
372 n := extra
373
374 nameBuf := make([]byte, 8)
375 for i := uint64(0); i < n; i++ {
376 nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000)
377 if err != nil {
378 return err
379 }
380
381 if !ok {
382 // Field doesn't exist on this type, so ignore it
383 if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil {
384 return err
385 }
386 continue
387 }
388
389 switch string(nameBuf[:nameLen]) {
390 // t.Ref (data.CIDLink) (struct)
391 case "ref":
392
393 {
394
395 if err := t.Ref.UnmarshalCBOR(cr); err != nil {
396 return xerrors.Errorf("unmarshaling t.Ref: %w", err)
397 }
398
399 }
400 // t.Size (int64) (int64)
401 case "size":
402 {
403 maj, extra, err := cr.ReadHeader()
404 if err != nil {
405 return err
406 }
407 var extraI int64
408 switch maj {
409 case cbg.MajUnsignedInt:
410 extraI = int64(extra)
411 if extraI < 0 {
412 return fmt.Errorf("int64 positive overflow")
413 }
414 case cbg.MajNegativeInt:
415 extraI = int64(extra)
416 if extraI < 0 {
417 return fmt.Errorf("int64 negative overflow")
418 }
419 extraI = -1 - extraI
420 default:
421 return fmt.Errorf("wrong type for int64 field: %d", maj)
422 }
423
424 t.Size = int64(extraI)
425 }
426 // t.LexiconTypeID (string) (string)
427 case "$type":
428
429 {
430 sval, err := cbg.ReadStringWithMax(cr, 1000000)
431 if err != nil {
432 return err
433 }
434
435 t.LexiconTypeID = string(sval)
436 }
437 // t.MimeType (string) (string)
438 case "mimeType":
439
440 {
441 sval, err := cbg.ReadStringWithMax(cr, 1000000)
442 if err != nil {
443 return err
444 }
445
446 t.MimeType = string(sval)
447 }
448
449 default:
450 // Field doesn't exist on this type, so ignore it
451 if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil {
452 return err
453 }
454 }
455 }
456
457 return nil
458}