-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcbor_gen.go
122 lines (95 loc) · 2.29 KB
/
cbor_gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
package f3
import (
"fmt"
"io"
"math"
"sort"
gpbft "github.com/filecoin-project/go-f3/gpbft"
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
var lengthBufPartialGMessage = []byte{130}
func (t *PartialGMessage) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
cw := cbg.NewCborWriter(w)
if _, err := cw.Write(lengthBufPartialGMessage); err != nil {
return err
}
// t.GMessage (gpbft.GMessage) (struct)
if err := t.GMessage.MarshalCBOR(cw); err != nil {
return err
}
// t.VoteValueKey (chainexchange.Key) (slice)
if len(t.VoteValueKey) > 32 {
return xerrors.Errorf("Byte array in field t.VoteValueKey was too long")
}
if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.VoteValueKey))); err != nil {
return err
}
if _, err := cw.Write(t.VoteValueKey); err != nil {
return err
}
return nil
}
func (t *PartialGMessage) UnmarshalCBOR(r io.Reader) (err error) {
*t = PartialGMessage{}
cr := cbg.NewCborReader(r)
maj, extra, err := cr.ReadHeader()
if err != nil {
return err
}
defer func() {
if err == io.EOF {
err = io.ErrUnexpectedEOF
}
}()
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.GMessage (gpbft.GMessage) (struct)
{
b, err := cr.ReadByte()
if err != nil {
return err
}
if b != cbg.CborNull[0] {
if err := cr.UnreadByte(); err != nil {
return err
}
t.GMessage = new(gpbft.GMessage)
if err := t.GMessage.UnmarshalCBOR(cr); err != nil {
return xerrors.Errorf("unmarshaling t.GMessage pointer: %w", err)
}
}
}
// t.VoteValueKey (chainexchange.Key) (slice)
maj, extra, err = cr.ReadHeader()
if err != nil {
return err
}
if extra > 32 {
return fmt.Errorf("t.VoteValueKey: byte array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
if extra > 0 {
t.VoteValueKey = make([]uint8, extra)
}
if _, err := io.ReadFull(cr, t.VoteValueKey); err != nil {
return err
}
return nil
}