Skip to content
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

rust: support encoding borrowed messages #986

Merged
merged 5 commits into from
May 18, 2021
Merged

rust: support encoding borrowed messages #986

merged 5 commits into from
May 18, 2021

Conversation

notoriaga
Copy link
Contributor

@notoriaga notoriaga commented May 18, 2021

needs swift-nav/dencode#2

Makes it so the encoders work with borrowed messages. Adds convenience functions to get a framed writer. Should we reexport dencode so people don't have to bring it in?

@notoriaga
Copy link
Contributor Author

notoriaga commented May 18, 2021

@john-michaelburke with these changes you can do something like

fn test() {
    use sbp::codec::{dencode::IterSinkExt, json::JsonEncoder, sbp::SbpEncoder};

    let input_file = std::fs::File::open("messages").unwrap();
    let log_file = std::fs::File::create("log").unwrap();
    let json_log_file = std::fs::File::create("json_log").unwrap();

    let mut bin_encoder = SbpEncoder::framed(log_file);
    let mut json_encoder = JsonEncoder::framed(json_log_file, serde_json::ser::CompactFormatter);

    for msg in iter_messages(input_file) {
        let msg = msg.unwrap();

        bin_encoder.send(&msg).unwrap();
        json_encoder.send(&msg).unwrap();
    }
}

@silverjam
Copy link
Contributor

... Should we reexport dencode so people don't have to bring it in?

👍

Copy link
Contributor

@silverjam silverjam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contingent on re-exporting dencode

Copy link
Contributor

@john-michaelburke john-michaelburke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this!!

@notoriaga notoriaga merged commit d589967 into master May 18, 2021
@notoriaga notoriaga deleted the steve/encoder branch May 18, 2021 23:26
notoriaga added a commit that referenced this pull request May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants