From 8ded9f6c05e39388918d3abbaa51b35a437690fa Mon Sep 17 00:00:00 2001 From: Antonin Bas Date: Mon, 13 Jan 2025 10:35:33 -0800 Subject: [PATCH] Do not embed Record interface into baseRecord (#398) 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 --- pkg/entities/record.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/entities/record.go b/pkg/entities/record.go index 8919f36a..a3a68ab9 100644 --- a/pkg/entities/record.go +++ b/pkg/entities/record.go @@ -52,7 +52,6 @@ type baseRecord struct { orderedElementList []InfoElementWithValue isDecoding bool len int - Record } type dataRecord struct { @@ -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 }