Skip to main content

Crate nmea_0183_rs

Crate nmea_0183_rs 

Source
Expand description

§nmea-0183-rs

Bidirectional NMEA 0183 parser/encoder with AIS decoding and transponder-message encoding.

§Architecture

raw line ──→ parse_frame() ──→ NmeaFrame { prefix, talker, sentence_type, fields }
                                    │
                     ┌──────────────┼──────────────┐
                     ▼              ▼               ▼
               $ + known      $ + unknown     ! AIVDM/AIVDO     AIS app sentences
                     │              │               │              │
                     ▼              ▼               ▼              ▼
              Typed struct    Raw fields      AisMessage enum   AIS sentence struct

§Public API

  • parse_frame / encode_frame — device-compatible frame APIs (always available)
  • parse_frame_strict / validate_sentence / encode_frame_strict — strict frame-envelope APIs (always available)
  • NmeaSentence — dispatch enum for all typed NMEA sentences (requires an NMEA feature)
  • NmeaEncodable — trait providing compatible and strict wire encoding (requires an NMEA feature)
  • ais — AIS decoder, transponder-message encoder, and !-prefixed AIS application sentences (requires ais, abm, or bbm)

NmeaFrame::to_sentence() re-encodes envelope data, including tag blocks, while normalizing checksums and CRLF. Keep the original line for exact bytes. NmeaSentence and ais::sentences::AisSentence also expose compatible and strict encoding; their Unknown variants own and preserve the captured envelope. Typed variants require the original frame to retain tags and the original talker. NMEA and ABM/BBM structs implement Default for construction with partial data. Their field parsers return Self directly; missing or malformed fields remain optional.

With ais, AisParser::decode() distinguishes ignored frames, pending fragments, messages and AisDecodeError through a Result. Use one parser per physical source. Position timestamps use ais::messages::PositionTimestamp, preserving the unavailable, manual-input, dead-reckoning and inoperative states.

§Partial construction and enum encoding

use nmea_0183_rs::{NmeaSentence, parse_frame};
use nmea_0183_rs::nmea::Dpt;
let value = NmeaSentence::Dpt(Dpt { depth: Some(4.1), ..Default::default() });
let output = value.to_sentence_strict("SD")?;
assert_eq!(NmeaSentence::parse(&parse_frame(&output)?), value);

Strict validation covers the shared frame envelope. It does not validate every formatter’s field semantics, serial transport settings, transmission timing, or multipart reassembly outside the AIS parser.

§Features

  • nmea (default): all 93 standard NMEA sentence types
  • nmea_proprietary (default) — all 16 proprietary NMEA sentence types
  • ais (default) — decoding for all numeric AIS Types 1-27, encoder support for Types 1/2/3, 4, 5, 9, 11, 12, 14, 18, 19, 21, 24 and 27, plus ABM, BBM and VSD sentences
  • Release 0.9.5 adds STN, XTR, ZDL, and ZFO: 101 NMEA formatters (85 standard, 16 proprietary) and 1076 passing all-features tests, including doctests
  • Release 0.9.6 adds ALM, FSI, MSK, and MSS: 105 NMEA formatters (89 standard, 16 proprietary) and 1113 passing all-features tests, including doctests
  • Release 0.9.7 adds HRM, NAK, ROR, and SPW, bringing coverage to 109 NMEA formatters (93 standard, 16 proprietary) and 1242 passing all-features tests, including doctests
  • dbs, dbt, dpt, … — individual sentence types

Re-exports§

pub use nmea::NmeaSentence;
pub use nmea::NmeaEncodable;

Modules§

ais
AIS (Automatic Identification System) message decoding and application-layer sentences.
nmea
NMEA 0183 sentence parsing and encoding.

Structs§

NmeaFrame
A parsed NMEA 0183 frame with references into the original input.

Enums§

ComplianceError
Errors reported by strict sentence validation.
EncodeError
Errors from encoding (invalid frame parts or field values).
FrameError
Errors from frame-level parsing (checksum, delimiters, tag blocks).
StrictEncodeError
Errors returned while building and strictly validating an encoded sentence.

Constants§

MAX_SENTENCE_LEN
Maximum NMEA 0183 sentence length, including the leading delimiter and CRLF.

Functions§

encode_frame
Encode fields into a valid NMEA 0183 sentence string.
encode_frame_strict
Encode a sentence and require the resulting wire representation to satisfy the strict frame rules.
parse_frame
Parse a raw NMEA 0183 line using device-compatible framing rules.
parse_frame_strict
Parse a complete sentence only when it satisfies the strict wire rules.
validate_sentence
Validate a complete NMEA 0183 sentence using the strict wire rules.