-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove duplicated code in ie_value.go #254
Conversation
Codecov Report
@@ Coverage Diff @@
## main #254 +/- ##
===========================================
+ Coverage 60.82% 73.60% +12.77%
===========================================
Files 18 18
Lines 3158 2580 -578
===========================================
- Hits 1921 1899 -22
+ Misses 1037 532 -505
+ Partials 200 149 -51
Flags with carried forward coverage won't be shown. Click here to find out more.
|
infoElem := &Unsigned8InfoElement{ | ||
value: val, | ||
} | ||
infoElem.element = element | ||
return infoElem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about writing it in this way:
return &Unsigned8InfoElement{
value: val,
element: element,
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Embedded element cannot be accessed like that.
pkg/entities/ie_value.go
Outdated
func (u16 *Unsigned16InfoElement) GetUnsigned16Value() (uint16, error) { | ||
return u16.value, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need to return error here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Not needed. The rest of the code that uses these get and set functions becomes simpler.
pkg/entities/ie_value.go
Outdated
return false, fmt.Errorf("accessing value of wrong data type") | ||
func (u16 *Unsigned16InfoElement) SetUnsigned16Value(val uint16) error { | ||
u16.value = val | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
bfe71ec
to
ec6b8b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM. only one nit.
pkg/entities/ie_value.go
Outdated
IsValueEmpty() bool | ||
GetLength() int | ||
ResetValue() | ||
} | ||
|
||
type Unsigned8InfoElement struct { | ||
value uint8 | ||
type BaseInfoElement struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to make this type public? I didn't see it is used outside this package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed. Modified.
There is lot of repeated code. Base structure can help in removing that.
ec6b8b9
to
514b71f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There is lot of repeated code. Base structure
can help in removing that.