Skip to content

Commit

Permalink
fix: use value receivers for MarshalXXX methods
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
setrofim committed Jul 3, 2024
1 parent 72283bb commit 31ad3e3
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions comid/classid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions comid/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions comid/flagsmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Check failure on line 200 in comid/flagsmap.go

View workflow job for this annotation

GitHub Actions / Lint

hugeParam: o is heavy (88 bytes); consider passing it by pointer (gocritic)

Check failure on line 200 in comid/flagsmap.go

View workflow job for this annotation

GitHub Actions / Lint

hugeParam: o is heavy (88 bytes); consider passing it by pointer (gocritic)
return encoding.SerializeStructToCBOR(em, o)
}

Expand All @@ -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) {

Check failure on line 210 in comid/flagsmap.go

View workflow job for this annotation

GitHub Actions / Lint

hugeParam: o is heavy (88 bytes); consider passing it by pointer (gocritic)

Check failure on line 210 in comid/flagsmap.go

View workflow job for this annotation

GitHub Actions / Lint

hugeParam: o is heavy (88 bytes); consider passing it by pointer (gocritic)
return encoding.SerializeStructToJSON(o)
}

Expand Down
4 changes: 2 additions & 2 deletions comid/measurement.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Check failure on line 377 in comid/measurement.go

View workflow job for this annotation

GitHub Actions / Lint

hugeParam: o is heavy (112 bytes); consider passing it by pointer (gocritic)

Check failure on line 377 in comid/measurement.go

View workflow job for this annotation

GitHub Actions / Lint

hugeParam: o is heavy (112 bytes); consider passing it by pointer (gocritic)
return encoding.SerializeStructToCBOR(em, o)
}

Expand All @@ -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) {

Check failure on line 387 in comid/measurement.go

View workflow job for this annotation

GitHub Actions / Lint

hugeParam: o is heavy (112 bytes); consider passing it by pointer (gocritic)

Check failure on line 387 in comid/measurement.go

View workflow job for this annotation

GitHub Actions / Lint

hugeParam: o is heavy (112 bytes); consider passing it by pointer (gocritic)
return encoding.SerializeStructToJSON(o)
}

Expand Down
4 changes: 2 additions & 2 deletions comid/triples.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions corim/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions corim/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down

0 comments on commit 31ad3e3

Please sign in to comment.