Skip to content

Conversation

@salsabiljb
Copy link
Contributor

@salsabiljb salsabiljb commented Sep 10, 2024

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 :
tag_block_parsing_test_tcp

Screenshot from 2024-10-07 02-43-05

Screenshot from 2024-10-07 02-43-20

Screenshot from 2024-08-21 15-36-34

Screenshot from 2024-08-21 15-37-19

Copy link

@github-advanced-security github-advanced-security bot left a 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.

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`

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`

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`

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`

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

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

cannot find macro `format` in this 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`

unresolved import `crate::lib::std::format`
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`

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`

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`

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`

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

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

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`

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`

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

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`

failed to resolve: use of undeclared crate or module `std`
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.

1 participant