Skip to content

Commit

Permalink
Add UnmarshalCBOR for AllocationID
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Oct 3, 2022
1 parent ed7f7a0 commit 9586bb6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions builtin/v9/verifreg/verifreg_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package verifreg

import (
"fmt"
"io"

cbg "github.com/whyrusleeping/cbor-gen"
Expand Down Expand Up @@ -98,6 +99,24 @@ func (a AllocationId) MarshalCBOR(w io.Writer) error {
return cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(a))
}

func (a *AllocationId) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
scratch := make([]byte, 8)

maj, extra, err := cbg.CborReadHeaderBuf(br, scratch)
if err != nil {
return err
}

if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}

*a = AllocationId(extra)

return nil
}

func (a AllocationId) Key() string {
return string(varint.ToUvarint(uint64(a)))
}
Expand Down

0 comments on commit 9586bb6

Please sign in to comment.