From d660ae245317fe35a612f9cf679626403345f217 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 13 May 2021 15:13:52 -0700 Subject: [PATCH] feat: take cbor adapters by-value when encoding This just makes our lives easier when using them. We can now, e.g., pass `CborInt(1)` to something that expects a `CBORMarshaler`. --- cbor_cid.go | 4 ++-- utils.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cbor_cid.go b/cbor_cid.go index ab4654a..57d6ec2 100644 --- a/cbor_cid.go +++ b/cbor_cid.go @@ -8,8 +8,8 @@ import ( type CborCid cid.Cid -func (c *CborCid) MarshalCBOR(w io.Writer) error { - return WriteCid(w, cid.Cid(*c)) +func (c CborCid) MarshalCBOR(w io.Writer) error { + return WriteCid(w, cid.Cid(c)) } func (c *CborCid) UnmarshalCBOR(r io.Reader) error { diff --git a/utils.go b/utils.go index 729dd30..2243ad4 100644 --- a/utils.go +++ b/utils.go @@ -626,8 +626,8 @@ func WriteCidBuf(buf []byte, w io.Writer, c cid.Cid) error { type CborBool bool -func (cb *CborBool) MarshalCBOR(w io.Writer) error { - return WriteBool(w, bool(*cb)) +func (cb CborBool) MarshalCBOR(w io.Writer) error { + return WriteBool(w, bool(cb)) } func (cb *CborBool) UnmarshalCBOR(r io.Reader) error { @@ -653,8 +653,8 @@ func (cb *CborBool) UnmarshalCBOR(r io.Reader) error { type CborInt int64 -func (ci *CborInt) MarshalCBOR(w io.Writer) error { - v := int64(*ci) +func (ci CborInt) MarshalCBOR(w io.Writer) error { + v := int64(ci) if v >= 0 { if err := WriteMajorTypeHeader(w, MajUnsignedInt, uint64(v)); err != nil { return err @@ -695,7 +695,7 @@ func (ci *CborInt) UnmarshalCBOR(r io.Reader) error { type CborTime time.Time -func (ct *CborTime) MarshalCBOR(w io.Writer) error { +func (ct CborTime) MarshalCBOR(w io.Writer) error { nsecs := ct.Time().UnixNano() cbi := CborInt(nsecs) -- GitLab