-
Notifications
You must be signed in to change notification settings - Fork 41
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
Add serde support #102
Add serde support #102
Conversation
src/parser.rs
Outdated
#[cfg_attr(feature = "serde", serde(serialize_with = "serialize_deque"))] | ||
#[cfg_attr(feature = "serde", serde(deserialize_with = "deserialize_deque"))] |
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.
#[cfg_attr(feature = "serde", serde(serialize_with = "serialize_deque"))] | |
#[cfg_attr(feature = "serde", serde(deserialize_with = "deserialize_deque"))] | |
#[cfg_attr(feature = "serde", serde(with = "serde_deque"))] |
mod serde_deque {
fn serialize(...) { ... }
fn deserialize(...) { ... }
}
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.
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.
Thanks for reviewing this PR @wiktorwieclaw . Your comment has been updated in the PR. We can fit it into 1 like but I have approved the PR as is.
src/parser.rs
Outdated
let mut deq: Deque<Vec<Option<Satellite>, 4>, 15> = Deque::new(); | ||
|
||
while let Some(v) = seq.next_element()? { | ||
deq.push_back(v).expect("Cannot deserialize"); |
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.
src/parser.rs
Outdated
type Value = Deque<Vec<Option<Satellite>, 4>, 15>; | ||
|
||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { | ||
formatter.write_str("deque") |
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.
you should be a bit more specific here
Cargo.toml
Outdated
arrayvec = { version = "0.7.2", default-features = false} | ||
chrono = { version = "0.4.19", default-features = false } | ||
heapless = "0.7.15" | ||
heapless = { version ="0.7.15"} |
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.
please make sure to fix the formatting
…k error, use more specified 'expecting' message
Thank you for the PR @0xf4lc0n! |
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.
Looks good so far.
There are only 2 things I managed to see for the Duration (de)serialization and I think it's good to discuss whether or not we should use camelCase
for the field names.
|
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## main #102 +/- ##
==========================================
- Coverage 79.46% 78.60% -0.86%
==========================================
Files 33 33
Lines 1193 1206 +13
==========================================
Hits 948 948
- Misses 245 258 +13
☔ View full report in Codecov by Sentry. |
Cargo.toml
Outdated
@@ -47,6 +48,14 @@ criterion = "0.4" | |||
[features] | |||
default = ["std", "all-sentences"] | |||
std = ["nom/std", "chrono/std", "arrayvec/std"] |
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.
Would you mind adding serde?/std
and serde_with?/std
to the std
feature list as well
I've opened this PR to bump the MSRV and update the std features: |
Signed-off-by: Lachezar Lechev <[email protected]>
This PR adds support for serialization and deserialization via serde as requested in #100.
Because SatsPack uses Deque which doesn't derive Serialize and Deserialize traits, a custom serialization/deserialization functions were created.