Skip to content

Commit

Permalink
Do not embed Record interface into baseRecord (#398)
Browse files Browse the repository at this point in the history
As far as I know this is an anti-pattern, and I am not sure why it was
done this way. baseRecord is just here to help reduce code duplication
in dataRecord and templateRecord, which both implement the Record
interface.

When embedding Recod in baseRecord, we 1) obfuscate things, making it
harder to detect at compile time that one of the record types is missing
a method implementation, and 2) increase the size of the baseRecord
struct needlessly (after this change the size is reduced from 88B down
to 72B on my machine).

Signed-off-by: Antonin Bas <[email protected]>
  • Loading branch information
antoninbas authored Jan 13, 2025
1 parent 509ba42 commit 8ded9f6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/entities/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ type baseRecord struct {
orderedElementList []InfoElementWithValue
isDecoding bool
len int
Record
}

type dataRecord struct {
Expand Down Expand Up @@ -248,6 +247,11 @@ func (d *dataRecord) AddInfoElement(element InfoElementWithValue) error {
return nil
}

// This method is only meaningful for template records.
func (d *dataRecord) GetMinDataRecordLen() uint16 {
return 0
}

func (d *dataRecord) GetRecordType() ContentType {
return Data
}
Expand Down

0 comments on commit 8ded9f6

Please sign in to comment.