Use map encoders for some structs

This commit is contained in:
Łukasz Magiera
2019-12-09 17:40:15 +01:00
parent 1d7dd4711d
commit 94df2c656e
13 changed files with 1285 additions and 769 deletions
+40 -31
View File
@@ -23,7 +23,7 @@ func (t *BlockSyncRequest) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Start ([]cid.Cid) (slice)
// t.Start ([]cid.Cid) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Start)))); err != nil {
return err
}
@@ -33,12 +33,12 @@ func (t *BlockSyncRequest) MarshalCBOR(w io.Writer) error {
}
}
// t.t.RequestLength (uint64) (uint64)
// t.RequestLength (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.RequestLength))); err != nil {
return err
}
// t.t.Options (uint64) (uint64)
// t.Options (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Options))); err != nil {
return err
}
@@ -60,13 +60,14 @@ func (t *BlockSyncRequest) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Start ([]cid.Cid) (slice)
// t.Start ([]cid.Cid) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
if extra > cbg.MaxLength {
return fmt.Errorf("t.Start: array too large (%d)", extra)
}
@@ -85,7 +86,7 @@ func (t *BlockSyncRequest) UnmarshalCBOR(r io.Reader) error {
t.Start[i] = c
}
// t.t.RequestLength (uint64) (uint64)
// t.RequestLength (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@@ -95,7 +96,7 @@ func (t *BlockSyncRequest) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.RequestLength = uint64(extra)
// t.t.Options (uint64) (uint64)
// t.Options (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@@ -117,7 +118,7 @@ func (t *BlockSyncResponse) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Chain ([]*blocksync.BSTipSet) (slice)
// t.Chain ([]*blocksync.BSTipSet) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Chain)))); err != nil {
return err
}
@@ -127,12 +128,12 @@ func (t *BlockSyncResponse) MarshalCBOR(w io.Writer) error {
}
}
// t.t.Status (uint64) (uint64)
// t.Status (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Status))); err != nil {
return err
}
// t.t.Message (string) (string)
// t.Message (string) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Message)))); err != nil {
return err
}
@@ -157,13 +158,14 @@ func (t *BlockSyncResponse) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Chain ([]*blocksync.BSTipSet) (slice)
// t.Chain ([]*blocksync.BSTipSet) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
if extra > cbg.MaxLength {
return fmt.Errorf("t.Chain: array too large (%d)", extra)
}
@@ -183,7 +185,7 @@ func (t *BlockSyncResponse) UnmarshalCBOR(r io.Reader) error {
t.Chain[i] = &v
}
// t.t.Status (uint64) (uint64)
// t.Status (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@@ -193,7 +195,7 @@ func (t *BlockSyncResponse) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.Status = uint64(extra)
// t.t.Message (string) (string)
// t.Message (string) (string)
{
sval, err := cbg.ReadString(br)
@@ -215,7 +217,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Blocks ([]*types.BlockHeader) (slice)
// t.Blocks ([]*types.BlockHeader) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Blocks)))); err != nil {
return err
}
@@ -225,7 +227,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error {
}
}
// t.t.BlsMessages ([]*types.Message) (slice)
// t.BlsMessages ([]*types.Message) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.BlsMessages)))); err != nil {
return err
}
@@ -235,7 +237,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error {
}
}
// t.t.BlsMsgIncludes ([][]uint64) (slice)
// t.BlsMsgIncludes ([][]uint64) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.BlsMsgIncludes)))); err != nil {
return err
}
@@ -250,7 +252,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error {
}
}
// t.t.SecpkMessages ([]*types.SignedMessage) (slice)
// t.SecpkMessages ([]*types.SignedMessage) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.SecpkMessages)))); err != nil {
return err
}
@@ -260,7 +262,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error {
}
}
// t.t.SecpkMsgIncludes ([][]uint64) (slice)
// t.SecpkMsgIncludes ([][]uint64) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.SecpkMsgIncludes)))); err != nil {
return err
}
@@ -292,13 +294,14 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Blocks ([]*types.BlockHeader) (slice)
// t.Blocks ([]*types.BlockHeader) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
if extra > cbg.MaxLength {
return fmt.Errorf("t.Blocks: array too large (%d)", extra)
}
@@ -318,13 +321,14 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
t.Blocks[i] = &v
}
// t.t.BlsMessages ([]*types.Message) (slice)
// t.BlsMessages ([]*types.Message) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
if extra > cbg.MaxLength {
return fmt.Errorf("t.BlsMessages: array too large (%d)", extra)
}
@@ -344,13 +348,14 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
t.BlsMessages[i] = &v
}
// t.t.BlsMsgIncludes ([][]uint64) (slice)
// t.BlsMsgIncludes ([][]uint64) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
if extra > cbg.MaxLength {
return fmt.Errorf("t.BlsMsgIncludes: array too large (%d)", extra)
}
@@ -370,7 +375,8 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
if err != nil {
return err
}
if extra > 8192 {
if extra > cbg.MaxLength {
return fmt.Errorf("t.BlsMsgIncludes[i]: array too large (%d)", extra)
}
@@ -397,13 +403,14 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.SecpkMessages ([]*types.SignedMessage) (slice)
// t.SecpkMessages ([]*types.SignedMessage) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
if extra > cbg.MaxLength {
return fmt.Errorf("t.SecpkMessages: array too large (%d)", extra)
}
@@ -423,13 +430,14 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
t.SecpkMessages[i] = &v
}
// t.t.SecpkMsgIncludes ([][]uint64) (slice)
// t.SecpkMsgIncludes ([][]uint64) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
if extra > cbg.MaxLength {
return fmt.Errorf("t.SecpkMsgIncludes: array too large (%d)", extra)
}
@@ -449,7 +457,8 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
if err != nil {
return err
}
if extra > 8192 {
if extra > cbg.MaxLength {
return fmt.Errorf("t.SecpkMsgIncludes[i]: array too large (%d)", extra)
}