From 9586bb652123af0e19eefd84142845b849d3f22b Mon Sep 17 00:00:00 2001 From: Aayush Date: Mon, 3 Oct 2022 13:16:26 -0400 Subject: [PATCH] Add UnmarshalCBOR for AllocationID --- builtin/v9/verifreg/verifreg_types.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/builtin/v9/verifreg/verifreg_types.go b/builtin/v9/verifreg/verifreg_types.go index 471b5d73..03963cba 100644 --- a/builtin/v9/verifreg/verifreg_types.go +++ b/builtin/v9/verifreg/verifreg_types.go @@ -1,6 +1,7 @@ package verifreg import ( + "fmt" "io" cbg "github.com/whyrusleeping/cbor-gen" @@ -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))) }