From 31ad3e37a8b717c3a164dea184fc3ca0fdec3300 Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Wed, 3 Jul 2024 16:53:20 +0100 Subject: [PATCH] fix: use value receivers for MarshalXXX methods Use value, rather than pointer, receivers for MarshalCBOR and MarshalJSON methods. Since those methods don't mutate the structures, pointers are not necessary, and using them prevents the methods from being invoked when marshaling an instance of that structure (rather than a pointer to one). This is not a huge deal as CoRIM fields typically use pointers, however it can lead to surprising results when playing with the structures on their own. Signed-off-by: Sergei Trofimov --- comid/classid.go | 4 ++-- comid/entity.go | 4 ++-- comid/flagsmap.go | 4 ++-- comid/measurement.go | 4 ++-- comid/triples.go | 4 ++-- corim/entity.go | 4 ++-- corim/meta.go | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/comid/classid.go b/comid/classid.go index feb375e9..d08dcde6 100644 --- a/comid/classid.go +++ b/comid/classid.go @@ -293,8 +293,8 @@ func (o TaggedImplID) Bytes() []byte { return o[:] } -func (o *TaggedImplID) MarshalJSON() ([]byte, error) { - return json.Marshal((*o)[:]) +func (o TaggedImplID) MarshalJSON() ([]byte, error) { + return json.Marshal((o)[:]) } func (o *TaggedImplID) UnmarshalJSON(data []byte) error { diff --git a/comid/entity.go b/comid/entity.go index 911c2111..c41c4f8d 100644 --- a/comid/entity.go +++ b/comid/entity.go @@ -90,7 +90,7 @@ func (o *Entity) UnmarshalCBOR(data []byte) error { } // MarshalCBOR serializes to CBOR -func (o *Entity) MarshalCBOR() ([]byte, error) { +func (o Entity) MarshalCBOR() ([]byte, error) { return encoding.SerializeStructToCBOR(em, o) } @@ -100,7 +100,7 @@ func (o *Entity) UnmarshalJSON(data []byte) error { } // MarshalJSON serializes to JSON -func (o *Entity) MarshalJSON() ([]byte, error) { +func (o Entity) MarshalJSON() ([]byte, error) { return encoding.SerializeStructToJSON(o) } diff --git a/comid/flagsmap.go b/comid/flagsmap.go index 94ed3e35..acbe3727 100644 --- a/comid/flagsmap.go +++ b/comid/flagsmap.go @@ -197,7 +197,7 @@ func (o *FlagsMap) UnmarshalCBOR(data []byte) error { } // MarshalCBOR serializes to CBOR -func (o *FlagsMap) MarshalCBOR() ([]byte, error) { +func (o FlagsMap) MarshalCBOR() ([]byte, error) { return encoding.SerializeStructToCBOR(em, o) } @@ -207,7 +207,7 @@ func (o *FlagsMap) UnmarshalJSON(data []byte) error { } // MarshalJSON serializes to JSON -func (o *FlagsMap) MarshalJSON() ([]byte, error) { +func (o FlagsMap) MarshalJSON() ([]byte, error) { return encoding.SerializeStructToJSON(o) } diff --git a/comid/measurement.go b/comid/measurement.go index 52fac579..c3150a08 100644 --- a/comid/measurement.go +++ b/comid/measurement.go @@ -374,7 +374,7 @@ func (o *Mval) UnmarshalCBOR(data []byte) error { } // MarshalCBOR serializes to CBOR -func (o *Mval) MarshalCBOR() ([]byte, error) { +func (o Mval) MarshalCBOR() ([]byte, error) { return encoding.SerializeStructToCBOR(em, o) } @@ -384,7 +384,7 @@ func (o *Mval) UnmarshalJSON(data []byte) error { } // MarshalJSON serializes to JSON -func (o *Mval) MarshalJSON() ([]byte, error) { +func (o Mval) MarshalJSON() ([]byte, error) { return encoding.SerializeStructToJSON(o) } diff --git a/comid/triples.go b/comid/triples.go index e3e9ac90..66164541 100644 --- a/comid/triples.go +++ b/comid/triples.go @@ -35,7 +35,7 @@ func (o *Triples) UnmarshalCBOR(data []byte) error { } // MarshalCBOR serializes to CBOR -func (o *Triples) MarshalCBOR() ([]byte, error) { +func (o Triples) MarshalCBOR() ([]byte, error) { return encoding.SerializeStructToCBOR(em, o) } @@ -45,7 +45,7 @@ func (o *Triples) UnmarshalJSON(data []byte) error { } // MarshalJSON serializes to JSON -func (o *Triples) MarshalJSON() ([]byte, error) { +func (o Triples) MarshalJSON() ([]byte, error) { return encoding.SerializeStructToJSON(o) } diff --git a/corim/entity.go b/corim/entity.go index 8a3169ac..f322ace1 100644 --- a/corim/entity.go +++ b/corim/entity.go @@ -103,7 +103,7 @@ func (o *Entity) UnmarshalCBOR(data []byte) error { } // MarshalCBOR serializes to CBOR -func (o *Entity) MarshalCBOR() ([]byte, error) { +func (o Entity) MarshalCBOR() ([]byte, error) { return encoding.SerializeStructToCBOR(em, o) } @@ -113,7 +113,7 @@ func (o *Entity) UnmarshalJSON(data []byte) error { } // MarshalJSON serializes to JSON -func (o *Entity) MarshalJSON() ([]byte, error) { +func (o Entity) MarshalJSON() ([]byte, error) { return encoding.SerializeStructToJSON(o) } diff --git a/corim/meta.go b/corim/meta.go index 9ce834e5..902c04c6 100644 --- a/corim/meta.go +++ b/corim/meta.go @@ -84,7 +84,7 @@ func (o *Signer) UnmarshalCBOR(data []byte) error { } // MarshalCBOR serializes to CBOR -func (o *Signer) MarshalCBOR() ([]byte, error) { +func (o Signer) MarshalCBOR() ([]byte, error) { return encoding.SerializeStructToCBOR(em, o) } @@ -94,7 +94,7 @@ func (o *Signer) UnmarshalJSON(data []byte) error { } // MarshalJSON serializes to JSON -func (o *Signer) MarshalJSON() ([]byte, error) { +func (o Signer) MarshalJSON() ([]byte, error) { return encoding.SerializeStructToJSON(o) }