-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add support for tag block, integrate UDP, TCP, file and single message parsing #24
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
base: main
Are you sure you want to change the base?
Conversation
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.
clippy found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
6278643 to
1baef9b
Compare
| use crate::messages::tag_block::TagBlock; | ||
| use crate::messages::AisMessage; | ||
| use crate::sentence::{AisFragments, AisParser}; | ||
| use crate::lib::std::error::Error as StdError; |
Check failure
Code scanning / clippy
unresolved import `crate::lib::std::error`
| use tokio::fs::File; | ||
| use tokio::io::{AsyncBufReadExt, BufReader}; | ||
| use tokio::net::{TcpStream, UdpSocket}; | ||
| use std::println; |
Check failure
Code scanning / clippy
unresolved import `std`
| use tokio::io::{AsyncBufReadExt, BufReader}; | ||
| use tokio::net::{TcpStream, UdpSocket}; | ||
| use std::println; | ||
| use std::eprintln; |
Check failure
Code scanning / clippy
unresolved import `std`
| /// | ||
| async fn parse_nmea_line(parser: &mut AisParser, line: &[u8]) { | ||
| let line_str = std::str::from_utf8(line).expect("Invalid UTF-8 sequence"); |
Check failure
Code scanning / clippy
failed to resolve: use of undeclared crate or module `std`
| /// * `address` - The address to bind to in the form "ip:port". | ||
| /// | ||
| pub async fn decode_from_udp(address: &str) -> Result<(), Box<dyn StdError>> { |
Check failure
Code scanning / clippy
cannot find type `Box` in this scope
| // Calculate the checksum | ||
| let calculated_checksum = calculate_checksum(key_value_part.as_bytes()); | ||
| if calculated_checksum != provided_checksum { | ||
| return Err(format!( |
Check failure
Code scanning / clippy
cannot find macro `format` in this scope
| use crate::messages::tag_block::TagBlock; | ||
| use crate::messages::AisMessage; | ||
| use crate::sentence::{AisFragments, AisParser}; | ||
| use crate::lib::std::error::Error as StdError; |
Check failure
Code scanning / clippy
unresolved import `crate::lib::std::error`
| use tokio::fs::File; | ||
| use tokio::io::{AsyncBufReadExt, BufReader}; | ||
| use tokio::net::{TcpStream, UdpSocket}; | ||
| use std::println; |
Check failure
Code scanning / clippy
unresolved import `std`
| use tokio::io::{AsyncBufReadExt, BufReader}; | ||
| use tokio::net::{TcpStream, UdpSocket}; | ||
| use std::println; | ||
| use std::eprintln; |
Check failure
Code scanning / clippy
unresolved import `std`
| /// | ||
| async fn parse_nmea_line(parser: &mut AisParser, line: &[u8]) { | ||
| let line_str = std::str::from_utf8(line).expect("Invalid UTF-8 sequence"); |
Check failure
Code scanning / clippy
failed to resolve: use of undeclared crate or module `std`
| /// * `address` - The address to bind to in the form "ip:port". | ||
| /// | ||
| pub async fn decode_from_udp(address: &str) -> Result<(), Box<dyn StdError>> { |
Check failure
Code scanning / clippy
cannot find type `Box` in this scope
|
|
||
| // Parse the provided checksum | ||
| let provided_checksum = u8::from_str_radix(checksum_str, 16).map_err(|_| { | ||
| "Invalid checksum format: checksum is not a valid hexadecimal number".to_string() |
Check failure
Code scanning / clippy
no method named `to_string` found for reference `&'static str` in the current scope
| use nom::number::complete::hex_u32; | ||
| use nom::sequence::{delimited, terminated}; | ||
| use nom::IResult; | ||
| use crate::lib::std::format; |
Check failure
Code scanning / clippy
unresolved import `crate::lib::std::format`
| pub fn parse(&mut self, line: &[u8], decode: bool) -> Result<AisFragments> { | ||
| pub fn parse(&mut self, line: &[u8], decode: bool) -> Result<(Option<TagBlock>, AisFragments)> { | ||
| // Convert the line to a UTF-8 string | ||
| let line_str = std::str::from_utf8(line).map_err(|_| "Invalid UTF-8 sequence")?; |
Check failure
Code scanning / clippy
failed to resolve: use of undeclared crate or module `std`
|
|
||
| // Check if the line contains a tag block | ||
| let (tag_block, _nmea_sentence) = if line_str.starts_with('\\') { | ||
| let parts: Vec<&str> = line_str.splitn(3, '\\').collect(); |
Check failure
Code scanning / clippy
cannot find type `Vec` in this scope
| self.verify_and_extend_data(&ais_sentence)?; | ||
| let mut data = AisRawData::default(); | ||
| lib::std::mem::swap(&mut data, &mut self.data); | ||
| std::mem::swap(&mut data, &mut self.data); |
Check failure
Code scanning / clippy
failed to resolve: use of undeclared crate or module `std`
I documented each change i did so ( cargo doc ) would be so helpful especially in the Tag Block part.
Previously, the library ignored these prefixes, but with the recent improvements, it now parses them effectively, preserving essential contextual metadata. The screenshot below demonstrates how the library is able to parse both types of messages with and without a tag block :
