From d7af5c67e9b01ac8b531c2a8a2e2891ee8732b9f Mon Sep 17 00:00:00 2001 From: Jeromy Date: Mon, 4 May 2020 15:19:48 -0700 Subject: [PATCH] update to latest cbor-gen --- api/cbor_gen.go | 123 +++++++++++-------- chain/blocksync/cbor_gen.go | 87 ++++++++------ chain/types/cbor_gen.go | 232 ++++++++++++++++++++++-------------- go.mod | 4 +- go.sum | 4 + node/hello/cbor_gen.go | 44 ++++--- paychmgr/cbor_gen.go | 63 +++++----- 7 files changed, 334 insertions(+), 223 deletions(-) diff --git a/api/cbor_gen.go b/api/cbor_gen.go index 46db528b6..85079d39a 100644 --- a/api/cbor_gen.go +++ b/api/cbor_gen.go @@ -23,15 +23,17 @@ func (t *PaymentInfo) MarshalCBOR(w io.Writer) error { return err } + scratch := make([]byte, 9) + // t.Channel (address.Address) (struct) if len("Channel") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Channel\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Channel")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Channel"))); err != nil { return err } - if _, err := w.Write([]byte("Channel")); err != nil { + if _, err := io.WriteString(w, "Channel"); err != nil { return err } @@ -44,10 +46,10 @@ func (t *PaymentInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"ChannelMessage\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("ChannelMessage")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("ChannelMessage"))); err != nil { return err } - if _, err := w.Write([]byte("ChannelMessage")); err != nil { + if _, err := io.WriteString(w, "ChannelMessage"); err != nil { return err } @@ -56,7 +58,7 @@ func (t *PaymentInfo) MarshalCBOR(w io.Writer) error { return err } } else { - if err := cbg.WriteCid(w, *t.ChannelMessage); err != nil { + if err := cbg.WriteCidBuf(scratch, w, *t.ChannelMessage); err != nil { return xerrors.Errorf("failed to write cid field t.ChannelMessage: %w", err) } } @@ -66,10 +68,10 @@ func (t *PaymentInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Vouchers\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Vouchers")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Vouchers"))); err != nil { return err } - if _, err := w.Write([]byte("Vouchers")); err != nil { + if _, err := io.WriteString(w, "Vouchers"); err != nil { return err } @@ -77,7 +79,7 @@ func (t *PaymentInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Vouchers was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Vouchers)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Vouchers))); err != nil { return err } for _, v := range t.Vouchers { @@ -90,8 +92,9 @@ func (t *PaymentInfo) MarshalCBOR(w io.Writer) error { func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -109,7 +112,7 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadString(br) + sval, err := cbg.ReadStringBuf(br, scratch) if err != nil { return err } @@ -156,7 +159,7 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error { // t.Vouchers ([]*paych.SignedVoucher) (slice) case "Vouchers": - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -199,19 +202,21 @@ func (t *SealedRef) MarshalCBOR(w io.Writer) error { return err } + scratch := make([]byte, 9) + // t.SectorID (abi.SectorNumber) (uint64) if len("SectorID") > cbg.MaxLength { return xerrors.Errorf("Value in field \"SectorID\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("SectorID")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("SectorID"))); err != nil { return err } - if _, err := w.Write([]byte("SectorID")); err != nil { + if _, err := io.WriteString(w, "SectorID"); err != nil { return err } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SectorID))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.SectorID)); err != nil { return err } @@ -220,14 +225,14 @@ func (t *SealedRef) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Offset\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Offset")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Offset"))); err != nil { return err } - if _, err := w.Write([]byte("Offset")); err != nil { + if _, err := io.WriteString(w, "Offset"); err != nil { return err } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Offset))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Offset)); err != nil { return err } @@ -236,14 +241,14 @@ func (t *SealedRef) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Size\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Size")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Size"))); err != nil { return err } - if _, err := w.Write([]byte("Size")); err != nil { + if _, err := io.WriteString(w, "Size"); err != nil { return err } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Size))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Size)); err != nil { return err } @@ -252,8 +257,9 @@ func (t *SealedRef) MarshalCBOR(w io.Writer) error { func (t *SealedRef) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -271,7 +277,7 @@ func (t *SealedRef) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadString(br) + sval, err := cbg.ReadStringBuf(br, scratch) if err != nil { return err } @@ -285,7 +291,7 @@ func (t *SealedRef) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -300,7 +306,7 @@ func (t *SealedRef) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -315,7 +321,7 @@ func (t *SealedRef) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -342,15 +348,17 @@ func (t *SealedRefs) MarshalCBOR(w io.Writer) error { return err } + scratch := make([]byte, 9) + // t.Refs ([]api.SealedRef) (slice) if len("Refs") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Refs\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Refs")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Refs"))); err != nil { return err } - if _, err := w.Write([]byte("Refs")); err != nil { + if _, err := io.WriteString(w, "Refs"); err != nil { return err } @@ -358,7 +366,7 @@ func (t *SealedRefs) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Refs was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Refs)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Refs))); err != nil { return err } for _, v := range t.Refs { @@ -371,8 +379,9 @@ func (t *SealedRefs) MarshalCBOR(w io.Writer) error { func (t *SealedRefs) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -390,7 +399,7 @@ func (t *SealedRefs) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadString(br) + sval, err := cbg.ReadStringBuf(br, scratch) if err != nil { return err } @@ -402,7 +411,7 @@ func (t *SealedRefs) UnmarshalCBOR(r io.Reader) error { // t.Refs ([]api.SealedRef) (slice) case "Refs": - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -445,15 +454,17 @@ func (t *SealTicket) MarshalCBOR(w io.Writer) error { return err } + scratch := make([]byte, 9) + // t.Value (abi.SealRandomness) (slice) if len("Value") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Value\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Value")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Value"))); err != nil { return err } - if _, err := w.Write([]byte("Value")); err != nil { + if _, err := io.WriteString(w, "Value"); err != nil { return err } @@ -461,9 +472,10 @@ func (t *SealTicket) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.Value was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Value)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Value))); err != nil { return err } + if _, err := w.Write(t.Value); err != nil { return err } @@ -473,19 +485,19 @@ func (t *SealTicket) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Epoch\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Epoch")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Epoch"))); err != nil { return err } - if _, err := w.Write([]byte("Epoch")); err != nil { + if _, err := io.WriteString(w, "Epoch"); err != nil { return err } if t.Epoch >= 0 { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Epoch))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Epoch)); err != nil { return err } } else { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.Epoch)-1)); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.Epoch-1)); err != nil { return err } } @@ -494,8 +506,9 @@ func (t *SealTicket) MarshalCBOR(w io.Writer) error { func (t *SealTicket) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -513,7 +526,7 @@ func (t *SealTicket) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadString(br) + sval, err := cbg.ReadStringBuf(br, scratch) if err != nil { return err } @@ -525,7 +538,7 @@ func (t *SealTicket) UnmarshalCBOR(r io.Reader) error { // t.Value (abi.SealRandomness) (slice) case "Value": - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -543,7 +556,7 @@ func (t *SealTicket) UnmarshalCBOR(r io.Reader) error { // t.Epoch (abi.ChainEpoch) (int64) case "Epoch": { - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) var extraI int64 if err != nil { return err @@ -583,15 +596,17 @@ func (t *SealSeed) MarshalCBOR(w io.Writer) error { return err } + scratch := make([]byte, 9) + // t.Value (abi.InteractiveSealRandomness) (slice) if len("Value") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Value\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Value")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Value"))); err != nil { return err } - if _, err := w.Write([]byte("Value")); err != nil { + if _, err := io.WriteString(w, "Value"); err != nil { return err } @@ -599,9 +614,10 @@ func (t *SealSeed) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.Value was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Value)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Value))); err != nil { return err } + if _, err := w.Write(t.Value); err != nil { return err } @@ -611,19 +627,19 @@ func (t *SealSeed) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Epoch\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Epoch")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Epoch"))); err != nil { return err } - if _, err := w.Write([]byte("Epoch")); err != nil { + if _, err := io.WriteString(w, "Epoch"); err != nil { return err } if t.Epoch >= 0 { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Epoch))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Epoch)); err != nil { return err } } else { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.Epoch)-1)); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.Epoch-1)); err != nil { return err } } @@ -632,8 +648,9 @@ func (t *SealSeed) MarshalCBOR(w io.Writer) error { func (t *SealSeed) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -651,7 +668,7 @@ func (t *SealSeed) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadString(br) + sval, err := cbg.ReadStringBuf(br, scratch) if err != nil { return err } @@ -663,7 +680,7 @@ func (t *SealSeed) UnmarshalCBOR(r io.Reader) error { // t.Value (abi.InteractiveSealRandomness) (slice) case "Value": - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -681,7 +698,7 @@ func (t *SealSeed) UnmarshalCBOR(r io.Reader) error { // t.Epoch (abi.ChainEpoch) (int64) case "Epoch": { - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) var extraI int64 if err != nil { return err diff --git a/chain/blocksync/cbor_gen.go b/chain/blocksync/cbor_gen.go index fbe7145d1..583a5b58d 100644 --- a/chain/blocksync/cbor_gen.go +++ b/chain/blocksync/cbor_gen.go @@ -14,38 +14,42 @@ import ( var _ = xerrors.Errorf +var lengthBufBlockSyncRequest = []byte{131} + func (t *BlockSyncRequest) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{131}); err != nil { + if _, err := w.Write(lengthBufBlockSyncRequest); err != nil { return err } + scratch := make([]byte, 9) + // t.Start ([]cid.Cid) (slice) if len(t.Start) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Start was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Start)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Start))); err != nil { return err } for _, v := range t.Start { - if err := cbg.WriteCid(w, v); err != nil { + if err := cbg.WriteCidBuf(scratch, w, v); err != nil { return xerrors.Errorf("failed writing cid field t.Start: %w", err) } } // t.RequestLength (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.RequestLength))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.RequestLength)); err != nil { return err } // t.Options (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Options))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Options)); err != nil { return err } @@ -54,8 +58,9 @@ func (t *BlockSyncRequest) MarshalCBOR(w io.Writer) error { func (t *BlockSyncRequest) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -69,7 +74,7 @@ func (t *BlockSyncRequest) UnmarshalCBOR(r io.Reader) error { // t.Start ([]cid.Cid) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -99,7 +104,7 @@ func (t *BlockSyncRequest) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -113,7 +118,7 @@ func (t *BlockSyncRequest) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -126,21 +131,25 @@ func (t *BlockSyncRequest) UnmarshalCBOR(r io.Reader) error { return nil } +var lengthBufBlockSyncResponse = []byte{131} + func (t *BlockSyncResponse) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{131}); err != nil { + if _, err := w.Write(lengthBufBlockSyncResponse); err != nil { return err } + scratch := make([]byte, 9) + // t.Chain ([]*blocksync.BSTipSet) (slice) if len(t.Chain) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Chain was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Chain)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Chain))); err != nil { return err } for _, v := range t.Chain { @@ -151,7 +160,7 @@ func (t *BlockSyncResponse) MarshalCBOR(w io.Writer) error { // t.Status (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Status))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Status)); err != nil { return err } @@ -160,10 +169,10 @@ func (t *BlockSyncResponse) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.Message was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Message)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Message))); err != nil { return err } - if _, err := w.Write([]byte(t.Message)); err != nil { + if _, err := io.WriteString(w, t.Message); err != nil { return err } return nil @@ -171,8 +180,9 @@ func (t *BlockSyncResponse) MarshalCBOR(w io.Writer) error { func (t *BlockSyncResponse) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -186,7 +196,7 @@ func (t *BlockSyncResponse) UnmarshalCBOR(r io.Reader) error { // t.Chain ([]*blocksync.BSTipSet) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -217,7 +227,7 @@ func (t *BlockSyncResponse) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -230,7 +240,7 @@ func (t *BlockSyncResponse) UnmarshalCBOR(r io.Reader) error { // t.Message (string) (string) { - sval, err := cbg.ReadString(br) + sval, err := cbg.ReadStringBuf(br, scratch) if err != nil { return err } @@ -240,21 +250,25 @@ func (t *BlockSyncResponse) UnmarshalCBOR(r io.Reader) error { return nil } +var lengthBufBSTipSet = []byte{133} + func (t *BSTipSet) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{133}); err != nil { + if _, err := w.Write(lengthBufBSTipSet); err != nil { return err } + scratch := make([]byte, 9) + // t.Blocks ([]*types.BlockHeader) (slice) if len(t.Blocks) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Blocks was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Blocks)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Blocks))); err != nil { return err } for _, v := range t.Blocks { @@ -268,7 +282,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.BlsMessages was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.BlsMessages)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.BlsMessages))); err != nil { return err } for _, v := range t.BlsMessages { @@ -282,7 +296,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.BlsMsgIncludes was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.BlsMsgIncludes)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.BlsMsgIncludes))); err != nil { return err } for _, v := range t.BlsMsgIncludes { @@ -290,7 +304,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field v was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(v)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(v))); err != nil { return err } for _, v := range v { @@ -305,7 +319,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.SecpkMessages was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.SecpkMessages)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.SecpkMessages))); err != nil { return err } for _, v := range t.SecpkMessages { @@ -319,7 +333,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.SecpkMsgIncludes was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.SecpkMsgIncludes)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.SecpkMsgIncludes))); err != nil { return err } for _, v := range t.SecpkMsgIncludes { @@ -327,7 +341,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field v was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(v)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(v))); err != nil { return err } for _, v := range v { @@ -341,8 +355,9 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error { func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -356,7 +371,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error { // t.Blocks ([]*types.BlockHeader) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -385,7 +400,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error { // t.BlsMessages ([]*types.Message) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -414,7 +429,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error { // t.BlsMsgIncludes ([][]uint64) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -437,7 +452,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error { var extra uint64 var err error - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -456,7 +471,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error { for j := 0; j < int(extra); j++ { - maj, val, err := cbg.CborReadHeader(br) + maj, val, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return xerrors.Errorf("failed to read uint64 for t.BlsMsgIncludes[i] slice: %w", err) } @@ -473,7 +488,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error { // t.SecpkMessages ([]*types.SignedMessage) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -502,7 +517,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error { // t.SecpkMsgIncludes ([][]uint64) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -525,7 +540,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error { var extra uint64 var err error - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -544,7 +559,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error { for j := 0; j < int(extra); j++ { - maj, val, err := cbg.CborReadHeader(br) + maj, val, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return xerrors.Errorf("failed to read uint64 for t.SecpkMsgIncludes[i] slice: %w", err) } diff --git a/chain/types/cbor_gen.go b/chain/types/cbor_gen.go index 7dca0a2ae..b52171797 100644 --- a/chain/types/cbor_gen.go +++ b/chain/types/cbor_gen.go @@ -16,15 +16,19 @@ import ( var _ = xerrors.Errorf +var lengthBufBlockHeader = []byte{143} + func (t *BlockHeader) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{143}); err != nil { + if _, err := w.Write(lengthBufBlockHeader); err != nil { return err } + scratch := make([]byte, 9) + // t.Miner (address.Address) (struct) if err := t.Miner.MarshalCBOR(w); err != nil { return err @@ -45,7 +49,7 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.BeaconEntries was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.BeaconEntries)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.BeaconEntries))); err != nil { return err } for _, v := range t.BeaconEntries { @@ -59,7 +63,7 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.WinPoStProof was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.WinPoStProof)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.WinPoStProof))); err != nil { return err } for _, v := range t.WinPoStProof { @@ -73,11 +77,11 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Parents was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Parents)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Parents))); err != nil { return err } for _, v := range t.Parents { - if err := cbg.WriteCid(w, v); err != nil { + if err := cbg.WriteCidBuf(scratch, w, v); err != nil { return xerrors.Errorf("failed writing cid field t.Parents: %w", err) } } @@ -89,30 +93,30 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error { // t.Height (abi.ChainEpoch) (int64) if t.Height >= 0 { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Height))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Height)); err != nil { return err } } else { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.Height)-1)); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.Height-1)); err != nil { return err } } // t.ParentStateRoot (cid.Cid) (struct) - if err := cbg.WriteCid(w, t.ParentStateRoot); err != nil { + if err := cbg.WriteCidBuf(scratch, w, t.ParentStateRoot); err != nil { return xerrors.Errorf("failed to write cid field t.ParentStateRoot: %w", err) } // t.ParentMessageReceipts (cid.Cid) (struct) - if err := cbg.WriteCid(w, t.ParentMessageReceipts); err != nil { + if err := cbg.WriteCidBuf(scratch, w, t.ParentMessageReceipts); err != nil { return xerrors.Errorf("failed to write cid field t.ParentMessageReceipts: %w", err) } // t.Messages (cid.Cid) (struct) - if err := cbg.WriteCid(w, t.Messages); err != nil { + if err := cbg.WriteCidBuf(scratch, w, t.Messages); err != nil { return xerrors.Errorf("failed to write cid field t.Messages: %w", err) } @@ -123,7 +127,7 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error { // t.Timestamp (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Timestamp))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Timestamp)); err != nil { return err } @@ -134,7 +138,7 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error { // t.ForkSignaling (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ForkSignaling))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.ForkSignaling)); err != nil { return err } @@ -143,8 +147,9 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error { func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -209,7 +214,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { } // t.BeaconEntries ([]types.BeaconEntry) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -238,7 +243,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { // t.WinPoStProof ([]abi.PoStProof) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -267,7 +272,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { // t.Parents ([]cid.Cid) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -304,7 +309,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { } // t.Height (abi.ChainEpoch) (int64) { - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) var extraI int64 if err != nil { return err @@ -388,7 +393,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -423,7 +428,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -436,23 +441,28 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { return nil } +var lengthBufTicket = []byte{129} + func (t *Ticket) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{129}); err != nil { + if _, err := w.Write(lengthBufTicket); err != nil { return err } + scratch := make([]byte, 9) + // t.VRFProof ([]uint8) (slice) if len(t.VRFProof) > cbg.ByteArrayMaxLen { return xerrors.Errorf("Byte array in field t.VRFProof was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.VRFProof)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.VRFProof))); err != nil { return err } + if _, err := w.Write(t.VRFProof); err != nil { return err } @@ -461,8 +471,9 @@ func (t *Ticket) MarshalCBOR(w io.Writer) error { func (t *Ticket) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -476,7 +487,7 @@ func (t *Ticket) UnmarshalCBOR(r io.Reader) error { // t.VRFProof ([]uint8) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -494,23 +505,28 @@ func (t *Ticket) UnmarshalCBOR(r io.Reader) error { return nil } +var lengthBufElectionProof = []byte{129} + func (t *ElectionProof) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{129}); err != nil { + if _, err := w.Write(lengthBufElectionProof); err != nil { return err } + scratch := make([]byte, 9) + // t.VRFProof ([]uint8) (slice) if len(t.VRFProof) > cbg.ByteArrayMaxLen { return xerrors.Errorf("Byte array in field t.VRFProof was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.VRFProof)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.VRFProof))); err != nil { return err } + if _, err := w.Write(t.VRFProof); err != nil { return err } @@ -519,8 +535,9 @@ func (t *ElectionProof) MarshalCBOR(w io.Writer) error { func (t *ElectionProof) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -534,7 +551,7 @@ func (t *ElectionProof) UnmarshalCBOR(r io.Reader) error { // t.VRFProof ([]uint8) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -552,22 +569,26 @@ func (t *ElectionProof) UnmarshalCBOR(r io.Reader) error { return nil } +var lengthBufMessage = []byte{137} + func (t *Message) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{137}); err != nil { + if _, err := w.Write(lengthBufMessage); err != nil { return err } + scratch := make([]byte, 9) + // t.Version (int64) (int64) if t.Version >= 0 { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Version))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Version)); err != nil { return err } } else { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.Version)-1)); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.Version-1)); err != nil { return err } } @@ -584,7 +605,7 @@ func (t *Message) MarshalCBOR(w io.Writer) error { // t.Nonce (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Nonce))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Nonce)); err != nil { return err } @@ -600,18 +621,18 @@ func (t *Message) MarshalCBOR(w io.Writer) error { // t.GasLimit (int64) (int64) if t.GasLimit >= 0 { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.GasLimit))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.GasLimit)); err != nil { return err } } else { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.GasLimit)-1)); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.GasLimit-1)); err != nil { return err } } // t.Method (abi.MethodNum) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Method))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Method)); err != nil { return err } @@ -620,9 +641,10 @@ func (t *Message) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.Params was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Params)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Params))); err != nil { return err } + if _, err := w.Write(t.Params); err != nil { return err } @@ -631,8 +653,9 @@ func (t *Message) MarshalCBOR(w io.Writer) error { func (t *Message) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -646,7 +669,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { // t.Version (int64) (int64) { - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) var extraI int64 if err != nil { return err @@ -691,7 +714,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -721,7 +744,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { } // t.GasLimit (int64) (int64) { - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) var extraI int64 if err != nil { return err @@ -748,7 +771,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -760,7 +783,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { } // t.Params ([]uint8) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -778,12 +801,14 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { return nil } +var lengthBufSignedMessage = []byte{130} + func (t *SignedMessage) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{130}); err != nil { + if _, err := w.Write(lengthBufSignedMessage); err != nil { return err } @@ -801,8 +826,9 @@ func (t *SignedMessage) MarshalCBOR(w io.Writer) error { func (t *SignedMessage) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -835,24 +861,28 @@ func (t *SignedMessage) UnmarshalCBOR(r io.Reader) error { return nil } +var lengthBufMsgMeta = []byte{130} + func (t *MsgMeta) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{130}); err != nil { + if _, err := w.Write(lengthBufMsgMeta); err != nil { return err } + scratch := make([]byte, 9) + // t.BlsMessages (cid.Cid) (struct) - if err := cbg.WriteCid(w, t.BlsMessages); err != nil { + if err := cbg.WriteCidBuf(scratch, w, t.BlsMessages); err != nil { return xerrors.Errorf("failed to write cid field t.BlsMessages: %w", err) } // t.SecpkMessages (cid.Cid) (struct) - if err := cbg.WriteCid(w, t.SecpkMessages); err != nil { + if err := cbg.WriteCidBuf(scratch, w, t.SecpkMessages); err != nil { return xerrors.Errorf("failed to write cid field t.SecpkMessages: %w", err) } @@ -861,8 +891,9 @@ func (t *MsgMeta) MarshalCBOR(w io.Writer) error { func (t *MsgMeta) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -901,30 +932,34 @@ func (t *MsgMeta) UnmarshalCBOR(r io.Reader) error { return nil } +var lengthBufActor = []byte{132} + func (t *Actor) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{132}); err != nil { + if _, err := w.Write(lengthBufActor); err != nil { return err } + scratch := make([]byte, 9) + // t.Code (cid.Cid) (struct) - if err := cbg.WriteCid(w, t.Code); err != nil { + if err := cbg.WriteCidBuf(scratch, w, t.Code); err != nil { return xerrors.Errorf("failed to write cid field t.Code: %w", err) } // t.Head (cid.Cid) (struct) - if err := cbg.WriteCid(w, t.Head); err != nil { + if err := cbg.WriteCidBuf(scratch, w, t.Head); err != nil { return xerrors.Errorf("failed to write cid field t.Head: %w", err) } // t.Nonce (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Nonce))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Nonce)); err != nil { return err } @@ -937,8 +972,9 @@ func (t *Actor) MarshalCBOR(w io.Writer) error { func (t *Actor) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -978,7 +1014,7 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -1000,22 +1036,26 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error { return nil } +var lengthBufMessageReceipt = []byte{131} + func (t *MessageReceipt) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{131}); err != nil { + if _, err := w.Write(lengthBufMessageReceipt); err != nil { return err } + scratch := make([]byte, 9) + // t.ExitCode (exitcode.ExitCode) (int64) if t.ExitCode >= 0 { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ExitCode))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.ExitCode)); err != nil { return err } } else { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.ExitCode)-1)); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.ExitCode-1)); err != nil { return err } } @@ -1025,20 +1065,21 @@ func (t *MessageReceipt) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.Return was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Return)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Return))); err != nil { return err } + if _, err := w.Write(t.Return); err != nil { return err } // t.GasUsed (int64) (int64) if t.GasUsed >= 0 { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.GasUsed))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.GasUsed)); err != nil { return err } } else { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.GasUsed)-1)); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.GasUsed-1)); err != nil { return err } } @@ -1047,8 +1088,9 @@ func (t *MessageReceipt) MarshalCBOR(w io.Writer) error { func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -1062,7 +1104,7 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error { // t.ExitCode (exitcode.ExitCode) (int64) { - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) var extraI int64 if err != nil { return err @@ -1087,7 +1129,7 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error { } // t.Return ([]uint8) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -1104,7 +1146,7 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error { } // t.GasUsed (int64) (int64) { - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) var extraI int64 if err != nil { return err @@ -1130,15 +1172,19 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error { return nil } +var lengthBufBlockMsg = []byte{131} + func (t *BlockMsg) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{131}); err != nil { + if _, err := w.Write(lengthBufBlockMsg); err != nil { return err } + scratch := make([]byte, 9) + // t.Header (types.BlockHeader) (struct) if err := t.Header.MarshalCBOR(w); err != nil { return err @@ -1149,11 +1195,11 @@ func (t *BlockMsg) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.BlsMessages was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.BlsMessages)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.BlsMessages))); err != nil { return err } for _, v := range t.BlsMessages { - if err := cbg.WriteCid(w, v); err != nil { + if err := cbg.WriteCidBuf(scratch, w, v); err != nil { return xerrors.Errorf("failed writing cid field t.BlsMessages: %w", err) } } @@ -1163,11 +1209,11 @@ func (t *BlockMsg) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.SecpkMessages was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.SecpkMessages)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.SecpkMessages))); err != nil { return err } for _, v := range t.SecpkMessages { - if err := cbg.WriteCid(w, v); err != nil { + if err := cbg.WriteCidBuf(scratch, w, v); err != nil { return xerrors.Errorf("failed writing cid field t.SecpkMessages: %w", err) } } @@ -1176,8 +1222,9 @@ func (t *BlockMsg) MarshalCBOR(w io.Writer) error { func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -1212,7 +1259,7 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error { } // t.BlsMessages ([]cid.Cid) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -1240,7 +1287,7 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error { // t.SecpkMessages ([]cid.Cid) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -1269,25 +1316,29 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error { return nil } +var lengthBufExpTipSet = []byte{131} + func (t *ExpTipSet) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{131}); err != nil { + if _, err := w.Write(lengthBufExpTipSet); err != nil { return err } + scratch := make([]byte, 9) + // t.Cids ([]cid.Cid) (slice) if len(t.Cids) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Cids was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Cids)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Cids))); err != nil { return err } for _, v := range t.Cids { - if err := cbg.WriteCid(w, v); err != nil { + if err := cbg.WriteCidBuf(scratch, w, v); err != nil { return xerrors.Errorf("failed writing cid field t.Cids: %w", err) } } @@ -1297,7 +1348,7 @@ func (t *ExpTipSet) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Blocks was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Blocks)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Blocks))); err != nil { return err } for _, v := range t.Blocks { @@ -1308,11 +1359,11 @@ func (t *ExpTipSet) MarshalCBOR(w io.Writer) error { // t.Height (abi.ChainEpoch) (int64) if t.Height >= 0 { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Height))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Height)); err != nil { return err } } else { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.Height)-1)); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.Height-1)); err != nil { return err } } @@ -1321,8 +1372,9 @@ func (t *ExpTipSet) MarshalCBOR(w io.Writer) error { func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -1336,7 +1388,7 @@ func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) error { // t.Cids ([]cid.Cid) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -1364,7 +1416,7 @@ func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) error { // t.Blocks ([]*types.BlockHeader) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -1393,7 +1445,7 @@ func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) error { // t.Height (abi.ChainEpoch) (int64) { - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) var extraI int64 if err != nil { return err @@ -1419,18 +1471,22 @@ func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) error { return nil } +var lengthBufBeaconEntry = []byte{130} + func (t *BeaconEntry) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{130}); err != nil { + if _, err := w.Write(lengthBufBeaconEntry); err != nil { return err } + scratch := make([]byte, 9) + // t.Round (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Round))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Round)); err != nil { return err } @@ -1439,9 +1495,10 @@ func (t *BeaconEntry) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.Data was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Data)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Data))); err != nil { return err } + if _, err := w.Write(t.Data); err != nil { return err } @@ -1450,8 +1507,9 @@ func (t *BeaconEntry) MarshalCBOR(w io.Writer) error { func (t *BeaconEntry) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -1467,7 +1525,7 @@ func (t *BeaconEntry) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -1479,7 +1537,7 @@ func (t *BeaconEntry) UnmarshalCBOR(r io.Reader) error { } // t.Data ([]uint8) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } diff --git a/go.mod b/go.mod index ec68e13b3..29eaddf5c 100644 --- a/go.mod +++ b/go.mod @@ -42,7 +42,7 @@ require ( github.com/ipfs/go-block-format v0.0.2 github.com/ipfs/go-blockservice v0.1.3 github.com/ipfs/go-car v0.0.3-0.20200304012825-b6769248bfef - github.com/ipfs/go-cid v0.0.5 + github.com/ipfs/go-cid v0.0.6-0.20200501230655-7c82f3b81c00 github.com/ipfs/go-datastore v0.4.4 github.com/ipfs/go-ds-badger2 v0.1.0 github.com/ipfs/go-filestore v0.0.2 @@ -98,7 +98,7 @@ require ( github.com/opentracing/opentracing-go v1.1.0 github.com/stretchr/testify v1.5.1 github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba - github.com/whyrusleeping/cbor-gen v0.0.0-20200501014322-5f9941ef88e0 + github.com/whyrusleeping/cbor-gen v0.0.0-20200504204219-64967432584d github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d go.opencensus.io v0.22.3 diff --git a/go.sum b/go.sum index 928cb2b9b..cbb79fa68 100644 --- a/go.sum +++ b/go.sum @@ -322,6 +322,8 @@ github.com/ipfs/go-cid v0.0.4-0.20191112011718-79e75dffeb10/go.mod h1:/BYOuUoxkE github.com/ipfs/go-cid v0.0.4/go.mod h1:4LLaPOQwmk5z9LBgQnpkivrx8BJjUyGwTXCd5Xfj6+M= github.com/ipfs/go-cid v0.0.5 h1:o0Ix8e/ql7Zb5UVUJEUfjsWCIY8t48++9lR8qi6oiJU= github.com/ipfs/go-cid v0.0.5/go.mod h1:plgt+Y5MnOey4vO4UlUazGqdbEXuFYitED67FexhXog= +github.com/ipfs/go-cid v0.0.6-0.20200501230655-7c82f3b81c00 h1:QN88Q0kT2QiDaLxpR/SDsqOBtNIEF/F3n96gSDUimkA= +github.com/ipfs/go-cid v0.0.6-0.20200501230655-7c82f3b81c00/go.mod h1:plgt+Y5MnOey4vO4UlUazGqdbEXuFYitED67FexhXog= github.com/ipfs/go-datastore v0.0.1/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= github.com/ipfs/go-datastore v0.0.5/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= github.com/ipfs/go-datastore v0.1.0/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= @@ -1010,6 +1012,8 @@ github.com/whyrusleeping/cbor-gen v0.0.0-20200414195334-429a0b5e922e h1:JY8o/ebU github.com/whyrusleeping/cbor-gen v0.0.0-20200414195334-429a0b5e922e/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI= github.com/whyrusleeping/cbor-gen v0.0.0-20200501014322-5f9941ef88e0 h1:dmdwCOVtJAm7qwONARangN4jgCisVFmSJ486JZ1LYaA= github.com/whyrusleeping/cbor-gen v0.0.0-20200501014322-5f9941ef88e0/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI= +github.com/whyrusleeping/cbor-gen v0.0.0-20200504204219-64967432584d h1:Y25auOnuZb/GuJvqMflRSDWBz8/HBRME8fiD+H8zLfs= +github.com/whyrusleeping/cbor-gen v0.0.0-20200504204219-64967432584d/go.mod h1:W5MvapuoHRP8rz4vxjwCK1pDqF1aQcWsV5PZ+AHbqdg= github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f h1:jQa4QT2UP9WYv2nzyawpKMOCl+Z/jW7djv2/J50lj9E= github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f/go.mod h1:p9UJB6dDgdPgMJZs7UjUOdulKyRr9fqkS+6JKAInPy8= github.com/whyrusleeping/go-ctrlnet v0.0.0-20180313164037-f564fbbdaa95/go.mod h1:SJqKCCPXRfBFCwXjfNT/skfsceF7+MBFLI2OrvuRA7g= diff --git a/node/hello/cbor_gen.go b/node/hello/cbor_gen.go index 5e0fc5bcd..8a4f9a1bc 100644 --- a/node/hello/cbor_gen.go +++ b/node/hello/cbor_gen.go @@ -14,36 +14,40 @@ import ( var _ = xerrors.Errorf +var lengthBufHelloMessage = []byte{132} + func (t *HelloMessage) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{132}); err != nil { + if _, err := w.Write(lengthBufHelloMessage); err != nil { return err } + scratch := make([]byte, 9) + // t.HeaviestTipSet ([]cid.Cid) (slice) if len(t.HeaviestTipSet) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.HeaviestTipSet was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.HeaviestTipSet)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.HeaviestTipSet))); err != nil { return err } for _, v := range t.HeaviestTipSet { - if err := cbg.WriteCid(w, v); err != nil { + if err := cbg.WriteCidBuf(scratch, w, v); err != nil { return xerrors.Errorf("failed writing cid field t.HeaviestTipSet: %w", err) } } // t.HeaviestTipSetHeight (abi.ChainEpoch) (int64) if t.HeaviestTipSetHeight >= 0 { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.HeaviestTipSetHeight))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.HeaviestTipSetHeight)); err != nil { return err } } else { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.HeaviestTipSetHeight)-1)); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.HeaviestTipSetHeight-1)); err != nil { return err } } @@ -55,7 +59,7 @@ func (t *HelloMessage) MarshalCBOR(w io.Writer) error { // t.GenesisHash (cid.Cid) (struct) - if err := cbg.WriteCid(w, t.GenesisHash); err != nil { + if err := cbg.WriteCidBuf(scratch, w, t.GenesisHash); err != nil { return xerrors.Errorf("failed to write cid field t.GenesisHash: %w", err) } @@ -64,8 +68,9 @@ func (t *HelloMessage) MarshalCBOR(w io.Writer) error { func (t *HelloMessage) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -79,7 +84,7 @@ func (t *HelloMessage) UnmarshalCBOR(r io.Reader) error { // t.HeaviestTipSet ([]cid.Cid) (slice) - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -107,7 +112,7 @@ func (t *HelloMessage) UnmarshalCBOR(r io.Reader) error { // t.HeaviestTipSetHeight (abi.ChainEpoch) (int64) { - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) var extraI int64 if err != nil { return err @@ -154,33 +159,37 @@ func (t *HelloMessage) UnmarshalCBOR(r io.Reader) error { return nil } +var lengthBufLatencyMessage = []byte{130} + func (t *LatencyMessage) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{130}); err != nil { + if _, err := w.Write(lengthBufLatencyMessage); err != nil { return err } + scratch := make([]byte, 9) + // t.TArrial (int64) (int64) if t.TArrial >= 0 { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.TArrial))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.TArrial)); err != nil { return err } } else { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.TArrial)-1)); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.TArrial-1)); err != nil { return err } } // t.TSent (int64) (int64) if t.TSent >= 0 { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.TSent))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.TSent)); err != nil { return err } } else { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.TSent)-1)); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.TSent-1)); err != nil { return err } } @@ -189,8 +198,9 @@ func (t *LatencyMessage) MarshalCBOR(w io.Writer) error { func (t *LatencyMessage) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -204,7 +214,7 @@ func (t *LatencyMessage) UnmarshalCBOR(r io.Reader) error { // t.TArrial (int64) (int64) { - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) var extraI int64 if err != nil { return err @@ -229,7 +239,7 @@ func (t *LatencyMessage) UnmarshalCBOR(r io.Reader) error { } // t.TSent (int64) (int64) { - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) var extraI int64 if err != nil { return err diff --git a/paychmgr/cbor_gen.go b/paychmgr/cbor_gen.go index 245ab15c1..6277bf465 100644 --- a/paychmgr/cbor_gen.go +++ b/paychmgr/cbor_gen.go @@ -22,15 +22,17 @@ func (t *VoucherInfo) MarshalCBOR(w io.Writer) error { return err } + scratch := make([]byte, 9) + // t.Voucher (paych.SignedVoucher) (struct) if len("Voucher") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Voucher\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Voucher")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Voucher"))); err != nil { return err } - if _, err := w.Write([]byte("Voucher")); err != nil { + if _, err := io.WriteString(w, "Voucher"); err != nil { return err } @@ -43,10 +45,10 @@ func (t *VoucherInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Proof\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Proof")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Proof"))); err != nil { return err } - if _, err := w.Write([]byte("Proof")); err != nil { + if _, err := io.WriteString(w, "Proof"); err != nil { return err } @@ -54,9 +56,10 @@ func (t *VoucherInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.Proof was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Proof)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Proof))); err != nil { return err } + if _, err := w.Write(t.Proof); err != nil { return err } @@ -65,8 +68,9 @@ func (t *VoucherInfo) MarshalCBOR(w io.Writer) error { func (t *VoucherInfo) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -84,7 +88,7 @@ func (t *VoucherInfo) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadString(br) + sval, err := cbg.ReadStringBuf(br, scratch) if err != nil { return err } @@ -118,7 +122,7 @@ func (t *VoucherInfo) UnmarshalCBOR(r io.Reader) error { // t.Proof ([]uint8) (slice) case "Proof": - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -150,15 +154,17 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return err } + scratch := make([]byte, 9) + // t.Channel (address.Address) (struct) if len("Channel") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Channel\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Channel")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Channel"))); err != nil { return err } - if _, err := w.Write([]byte("Channel")); err != nil { + if _, err := io.WriteString(w, "Channel"); err != nil { return err } @@ -171,10 +177,10 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Control\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Control")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Control"))); err != nil { return err } - if _, err := w.Write([]byte("Control")); err != nil { + if _, err := io.WriteString(w, "Control"); err != nil { return err } @@ -187,10 +193,10 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Target\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Target")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Target"))); err != nil { return err } - if _, err := w.Write([]byte("Target")); err != nil { + if _, err := io.WriteString(w, "Target"); err != nil { return err } @@ -203,14 +209,14 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Direction\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Direction")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Direction"))); err != nil { return err } - if _, err := w.Write([]byte("Direction")); err != nil { + if _, err := io.WriteString(w, "Direction"); err != nil { return err } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Direction))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Direction)); err != nil { return err } @@ -219,10 +225,10 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Vouchers\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Vouchers")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Vouchers"))); err != nil { return err } - if _, err := w.Write([]byte("Vouchers")); err != nil { + if _, err := io.WriteString(w, "Vouchers"); err != nil { return err } @@ -230,7 +236,7 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Vouchers was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Vouchers)))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Vouchers))); err != nil { return err } for _, v := range t.Vouchers { @@ -244,14 +250,14 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"NextLane\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("NextLane")))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("NextLane"))); err != nil { return err } - if _, err := w.Write([]byte("NextLane")); err != nil { + if _, err := io.WriteString(w, "NextLane"); err != nil { return err } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.NextLane))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.NextLane)); err != nil { return err } @@ -260,8 +266,9 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) + scratch := make([]byte, 8) - maj, extra, err := cbg.CborReadHeader(br) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -279,7 +286,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadString(br) + sval, err := cbg.ReadStringBuf(br, scratch) if err != nil { return err } @@ -323,7 +330,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -336,7 +343,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { // t.Vouchers ([]*paychmgr.VoucherInfo) (slice) case "Vouchers": - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } @@ -368,7 +375,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeader(br) + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err }