2022-03-08 21:48:08 +00:00
|
|
|
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
|
|
|
|
|
|
|
package shedgen
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"math"
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
cid "github.com/ipfs/go-cid"
|
|
|
|
cbg "github.com/whyrusleeping/cbor-gen"
|
|
|
|
xerrors "golang.org/x/xerrors"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = xerrors.Errorf
|
|
|
|
var _ = cid.Undef
|
|
|
|
var _ = math.E
|
|
|
|
var _ = sort.Sort
|
|
|
|
|
|
|
|
func (t *CarbNode) MarshalCBOR(w io.Writer) error {
|
|
|
|
if t == nil {
|
|
|
|
_, err := w.Write(cbg.CborNull)
|
|
|
|
return err
|
|
|
|
}
|
2022-04-20 21:34:28 +00:00
|
|
|
|
|
|
|
cw := cbg.NewCborWriter(w)
|
|
|
|
|
|
|
|
if _, err := cw.Write([]byte{161}); err != nil {
|
2022-03-08 21:48:08 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// t.Sub ([]cid.Cid) (slice)
|
|
|
|
if len("Sub") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"Sub\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Sub"))); err != nil {
|
2022-03-08 21:48:08 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := io.WriteString(w, string("Sub")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(t.Sub) > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Slice value in field t.Sub was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Sub))); err != nil {
|
2022-03-08 21:48:08 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, v := range t.Sub {
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cbg.WriteCid(w, v); err != nil {
|
2022-03-08 21:48:08 +00:00
|
|
|
return xerrors.Errorf("failed writing cid field t.Sub: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func (t *CarbNode) UnmarshalCBOR(r io.Reader) (err error) {
|
2022-03-08 21:48:08 +00:00
|
|
|
*t = CarbNode{}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
cr := cbg.NewCborReader(r)
|
2022-03-08 21:48:08 +00:00
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
maj, extra, err := cr.ReadHeader()
|
2022-03-08 21:48:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-04-20 21:34:28 +00:00
|
|
|
defer func() {
|
|
|
|
if err == io.EOF {
|
|
|
|
err = io.ErrUnexpectedEOF
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2022-03-08 21:48:08 +00:00
|
|
|
if maj != cbg.MajMap {
|
|
|
|
return fmt.Errorf("cbor input should be of type map")
|
|
|
|
}
|
|
|
|
|
|
|
|
if extra > cbg.MaxLength {
|
|
|
|
return fmt.Errorf("CarbNode: map struct too large (%d)", extra)
|
|
|
|
}
|
|
|
|
|
|
|
|
var name string
|
|
|
|
n := extra
|
|
|
|
|
|
|
|
for i := uint64(0); i < n; i++ {
|
|
|
|
|
|
|
|
{
|
2022-04-20 21:34:28 +00:00
|
|
|
sval, err := cbg.ReadString(cr)
|
2022-03-08 21:48:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
name = string(sval)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch name {
|
|
|
|
// t.Sub ([]cid.Cid) (slice)
|
|
|
|
case "Sub":
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
maj, extra, err = cr.ReadHeader()
|
2022-03-08 21:48:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if extra > cbg.MaxLength {
|
|
|
|
return fmt.Errorf("t.Sub: array too large (%d)", extra)
|
|
|
|
}
|
|
|
|
|
|
|
|
if maj != cbg.MajArray {
|
|
|
|
return fmt.Errorf("expected cbor array")
|
|
|
|
}
|
|
|
|
|
|
|
|
if extra > 0 {
|
|
|
|
t.Sub = make([]cid.Cid, extra)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < int(extra); i++ {
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
c, err := cbg.ReadCid(cr)
|
2022-03-08 21:48:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("reading cid field t.Sub failed: %w", err)
|
|
|
|
}
|
|
|
|
t.Sub[i] = c
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Field doesn't exist on this type, so ignore it
|
|
|
|
cbg.ScanForLinks(r, func(cid.Cid) {})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|