Skip to content

Commit

Permalink
Merge pull request #388 from blinklabs-io/feat/cbor-tag-rational
Browse files Browse the repository at this point in the history
feat: support for decoding rational numbers in CBOR
  • Loading branch information
agaffney authored Oct 1, 2023
2 parents e75e75c + 4665cee commit 759464f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cbor/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ const (
CBOR_MAX_UINT_SIMPLE uint8 = 0x17

// Useful tag numbers
CborTagSet = 258
CborTagMap = 259
CborTagRational = 30
CborTagSet = 258
CborTagMap = 259
)

// Create an alias for RawMessage for convenience
Expand Down
6 changes: 6 additions & 0 deletions cbor/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ func (v *Value) UnmarshalCBOR(data []byte) error {
return err
}
switch tmpTag.Number {
case CborTagRational:
var tmpRat []int64
if _, err := Decode(tmpTag.Content, &tmpRat); err != nil {
return err
}
v.value = big.NewRat(tmpRat[0], tmpRat[1])
case CborTagSet:
return v.processArray(tmpTag.Content)
case CborTagMap:
Expand Down

0 comments on commit 759464f

Please sign in to comment.