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