github.com/filecoin-project/specs-actors/v4@v4.0.2/actors/builtin/cron/cbor_gen.go (about) 1 // Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT. 2 3 package cron 4 5 import ( 6 "fmt" 7 "io" 8 9 abi "github.com/filecoin-project/go-state-types/abi" 10 cbg "github.com/whyrusleeping/cbor-gen" 11 xerrors "golang.org/x/xerrors" 12 ) 13 14 var _ = xerrors.Errorf 15 16 var lengthBufState = []byte{129} 17 18 func (t *State) MarshalCBOR(w io.Writer) error { 19 if t == nil { 20 _, err := w.Write(cbg.CborNull) 21 return err 22 } 23 if _, err := w.Write(lengthBufState); err != nil { 24 return err 25 } 26 27 scratch := make([]byte, 9) 28 29 // t.Entries ([]cron.Entry) (slice) 30 if len(t.Entries) > cbg.MaxLength { 31 return xerrors.Errorf("Slice value in field t.Entries was too long") 32 } 33 34 if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Entries))); err != nil { 35 return err 36 } 37 for _, v := range t.Entries { 38 if err := v.MarshalCBOR(w); err != nil { 39 return err 40 } 41 } 42 return nil 43 } 44 45 func (t *State) UnmarshalCBOR(r io.Reader) error { 46 *t = State{} 47 48 br := cbg.GetPeeker(r) 49 scratch := make([]byte, 8) 50 51 maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) 52 if err != nil { 53 return err 54 } 55 if maj != cbg.MajArray { 56 return fmt.Errorf("cbor input should be of type array") 57 } 58 59 if extra != 1 { 60 return fmt.Errorf("cbor input had wrong number of fields") 61 } 62 63 // t.Entries ([]cron.Entry) (slice) 64 65 maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) 66 if err != nil { 67 return err 68 } 69 70 if extra > cbg.MaxLength { 71 return fmt.Errorf("t.Entries: array too large (%d)", extra) 72 } 73 74 if maj != cbg.MajArray { 75 return fmt.Errorf("expected cbor array") 76 } 77 78 if extra > 0 { 79 t.Entries = make([]Entry, extra) 80 } 81 82 for i := 0; i < int(extra); i++ { 83 84 var v Entry 85 if err := v.UnmarshalCBOR(br); err != nil { 86 return err 87 } 88 89 t.Entries[i] = v 90 } 91 92 return nil 93 } 94 95 var lengthBufEntry = []byte{130} 96 97 func (t *Entry) MarshalCBOR(w io.Writer) error { 98 if t == nil { 99 _, err := w.Write(cbg.CborNull) 100 return err 101 } 102 if _, err := w.Write(lengthBufEntry); err != nil { 103 return err 104 } 105 106 scratch := make([]byte, 9) 107 108 // t.Receiver (address.Address) (struct) 109 if err := t.Receiver.MarshalCBOR(w); err != nil { 110 return err 111 } 112 113 // t.MethodNum (abi.MethodNum) (uint64) 114 115 if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.MethodNum)); err != nil { 116 return err 117 } 118 119 return nil 120 } 121 122 func (t *Entry) UnmarshalCBOR(r io.Reader) error { 123 *t = Entry{} 124 125 br := cbg.GetPeeker(r) 126 scratch := make([]byte, 8) 127 128 maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) 129 if err != nil { 130 return err 131 } 132 if maj != cbg.MajArray { 133 return fmt.Errorf("cbor input should be of type array") 134 } 135 136 if extra != 2 { 137 return fmt.Errorf("cbor input had wrong number of fields") 138 } 139 140 // t.Receiver (address.Address) (struct) 141 142 { 143 144 if err := t.Receiver.UnmarshalCBOR(br); err != nil { 145 return xerrors.Errorf("unmarshaling t.Receiver: %w", err) 146 } 147 148 } 149 // t.MethodNum (abi.MethodNum) (uint64) 150 151 { 152 153 maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) 154 if err != nil { 155 return err 156 } 157 if maj != cbg.MajUnsignedInt { 158 return fmt.Errorf("wrong type for uint64 field") 159 } 160 t.MethodNum = abi.MethodNum(extra) 161 162 } 163 return nil 164 }