Crate sbp[][src]

Expand description

Native implementation of decoding of SBP (Swift Binary Protocol) used by products made by Swift Navigation. For language agnostic description of the protocol please see the protocol specification documentation.

Example: Print log messages

This example shows how to read messages from stdin and print the contents of each message MsgLog to stderr.

use std::convert::TryFrom;
use std::error::Error;
use std::io;
use std::process;

use sbp::messages::logging::MsgLog;

fn example() -> Result<(), Box<dyn Error>> {
    let messages = sbp::iter_messages(io::stdin());
    for msg in messages {
        // The iterator yields Result<Sbp, Error>, so we check the error here.
        let msg = msg?;
        match MsgLog::try_from(msg) {
            Ok(msg) => eprintln!("{}", msg.text),
            _ => {}
        }
    }
    Ok(())
}

fn main() {
    if let Err(err) = example() {
        eprintln!("error: {}", err);
        process::exit(1);
    }
}

Example: Filter by sender id and write to stdout

This example shows how to read messages from stdin and forward messages with a matching sender_id to stdout.

use std::error::Error;
use std::io;
use std::process;

use sbp::{SbpEncoder, SbpMessage};

fn example(sender_id: u16) -> Result<(), Box<dyn Error>> {
    let messages = sbp::iter_messages(io::stdin());
    let messages = messages.filter_map(|msg| match msg {
        Ok(msg) if msg.sender_id() == Some(sender_id) => Some(msg),
        _ => None,
    });
    SbpEncoder::new(io::stdout()).send_all(messages)?;
    Ok(())
}

fn main() {
    if let Err(err) = example(42) {
        eprintln!("error: {}", err);
        process::exit(1);
    }
}

Modules

SBP message definitions.

Extra adaptors for iterators of Sbp messages.

Structs

The wire representation of an SBP message.

Writes Sbp messages into a writer.

Fixed or variable length string and its encoding.

Enums

All errors that can occur while reading messages.

Represents any SBP message.

All errors that can occur while writing messages.

Constants

Length of the crc of the payload.

Length of the header section.

Max length of a frame (header + payload + crc).

Max length of the variable-sized payload field.

Denotes the start of frame transmission.

Traits

An Iterator blanket implementation that provides extra adaptors for iterators of Sbp messages.

Common functionality available to all SBP messages.

Functions

Deserialize the IO stream into an iterator of messages.

Serialize the given message as a byte vector.

Serialize the given message into the IO stream.