File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -93,11 +93,19 @@ type Rat struct {
93
93
}
94
94
95
95
func (r * Rat ) UnmarshalCBOR (cborData []byte ) error {
96
- tmpRat := []int64 {}
96
+ tmpRat := []uint64 {}
97
97
if _ , err := Decode (cborData , & tmpRat ); err != nil {
98
98
return err
99
99
}
100
- r .Rat = big .NewRat (tmpRat [0 ], tmpRat [1 ])
100
+ // Convert numerator and denominator to big.Int
101
+ // It's necessary to do this to support num/denom larger than int64 (up to uint64)
102
+ tmpNum := new (big.Int )
103
+ tmpNum .SetUint64 (tmpRat [0 ])
104
+ tmpDenom := new (big.Int )
105
+ tmpDenom .SetUint64 (tmpRat [1 ])
106
+ // Create new big.Rat with num/denom set to big.Int values above
107
+ r .Rat = new (big.Rat )
108
+ r .Rat .SetFrac (tmpNum , tmpDenom )
101
109
return nil
102
110
}
103
111
Original file line number Diff line number Diff line change @@ -54,6 +54,15 @@ var tagsTestDefs = []struct {
54
54
},
55
55
),
56
56
},
57
+ {
58
+ cborHex : "d81e821b80000000000000011b8ac7230489e80000" ,
59
+ object : cbor.Rat {
60
+ Rat : new (big.Rat ).SetFrac (
61
+ new (big.Int ).SetUint64 (9223372036854775809 ),
62
+ new (big.Int ).SetUint64 (10000000000000000000 ),
63
+ ),
64
+ },
65
+ },
57
66
}
58
67
59
68
func TestTagsDecode (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments