-
Notifications
You must be signed in to change notification settings - Fork 109
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
Deprecate SetData method #288
Conversation
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #288 +/- ##
==========================================
- Coverage 73.95% 73.43% -0.52%
==========================================
Files 43 43
Lines 2338 2338
==========================================
- Hits 1729 1717 -12
- Misses 378 390 +12
Partials 231 231
☔ View full report in Codecov by Sentry. |
return nil | ||
} | ||
|
||
bin, ok := data.(*Binary) | ||
bin, ok := v.(*Binary) |
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.
@mfdeveloper508 here and in the rest of the fields, we don't need f.data
anymore. Before, it was used in SetData
and was a pointer that was used when we set and get "data". With Marhsal and Unmarshl - we don't need to store the pointer to the field type as we use field value directly.
f.data = bin // <- the field can be removed
if bin.value != nil {
f.value = bin.value
}
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.
#289
right fixed in next pr
return nil | ||
} | ||
|
||
bmap, ok := data.(*Bitmap) | ||
bmap, ok := v.(*Bitmap) |
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.
In this field, we need data
as it's basically value
- it stores the value of the field. Please, don't be confused with my previous statement that we should remove data
from all fields. When data *String
(or pointer to other field type - then we should remove it), but here - data
has the same purpose as value
in other fields. It just has different name.
@@ -23,7 +23,7 @@ type Field interface { | |||
// Bytes returns binary representation of the field Value | |||
Bytes() ([]byte, error) | |||
|
|||
// Deprecated. Use Marshal intead. | |||
// Deprecated. Use Marshal instead. |
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!
return nil | ||
} | ||
|
||
str, ok := data.(*Hex) | ||
str, ok := v.(*Hex) |
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.
below, we can remove f.data
return nil | ||
} | ||
|
||
num, ok := data.(*Numeric) | ||
num, ok := v.(*Numeric) |
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.
here we can remove data
as well
packed, err = numeric.Pack() | ||
require.NoError(t, err) | ||
require.Equal(t, " 9876", string(packed)) | ||
|
||
numeric = NewNumeric(spec) | ||
data := NewNumericValue(0) | ||
numeric.SetData(data) | ||
numeric.Marshal(data) |
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.
This test will fail after we remove data
from the Numeric
field. The behavior of SetData
is slightly different from Marshal
. Just test that Marshal
sets value and Unmarshal
sets value back to the arg.
return nil | ||
} | ||
|
||
str, ok := data.(*String) | ||
str, ok := v.(*String) |
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.
f.data
can be removed from the String
field
packed, err = str.Pack() | ||
require.NoError(t, err) | ||
require.Equal(t, " hello", string(packed)) | ||
|
||
str = NewString(spec) | ||
data := NewStringValue("") | ||
str.SetData(data) | ||
str.Marshal(data) | ||
length, err = str.Unpack([]byte(" olleh")) | ||
require.NoError(t, err) | ||
require.Equal(t, 10, length) | ||
require.Equal(t, "olleh", data.Value()) |
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.
This test will also fail as if we remove data
it will no longer be used in Unpack
(internally SetBytes
). Just test Marshal
and Unmarshal
.
return nil | ||
} | ||
|
||
track, ok := data.(*Track1) | ||
track, ok := v.(*Track1) |
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.
f.data
can be removed from the Track1
return nil | ||
} | ||
|
||
track, ok := data.(*Track2) | ||
track, ok := v.(*Track2) |
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.
f.data
can be removed from Track2
return nil | ||
} | ||
|
||
track, ok := data.(*Track3) | ||
track, ok := v.(*Track3) |
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.
here we can also remove f.data
.
@mfdeveloper508 thanks for breaking down your PR into smaller ones. For this PR the summary of my review is:
|
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!
#278