Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: clippy
run: cargo clippy --verbose
run: cargo clippy --verbose -- -D warnings
21 changes: 18 additions & 3 deletions src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ impl DTVCCPacket {
}
}

/// Whether this packet is currently empty and contains no [`Service`]s.
///
/// # Examples
/// ```
/// # use cea708_types::{*, tables::*};
/// let mut packet = DTVCCPacket::new(2);
/// assert!(packet.is_empty());
/// let mut service = Service::new(1);
/// service.push_code(&Code::LatinCapitalA).unwrap();
/// packet.push_service(service);
/// assert!(!packet.is_empty());
/// ```
pub fn is_empty(&self) -> bool {
self.services.is_empty()
}

/// Push a completed service block into this [DTVCCPacket]
///
/// # Examples
Expand All @@ -83,7 +99,6 @@ impl DTVCCPacket {
/// assert_eq!(3, packet.len());
/// ```
pub fn push_service(&mut self, service: Service) -> Result<(), WriterError> {
// TODO: fail if we would overrun max size
if service.len() > self.free_space() {
return Err(WriterError::WouldOverflow(
service.len() - self.free_space(),
Expand Down Expand Up @@ -146,7 +161,7 @@ impl DTVCCPacket {
while offset < data.len() {
let service = Service::parse(&data[offset..])?;
trace!("parsed service {service:?}, len:{}", service.len());
if service.len() == 0 {
if service.is_empty() {
offset += 1;
continue;
}
Expand Down Expand Up @@ -351,7 +366,7 @@ impl Service {
/// # Errors
///
/// * [ParserError::LengthMismatch] if the length of the data is less than the size advertised in the
/// header
/// header
///
/// # Examples
/// ```
Expand Down
Loading