nitf_rs/headers/
mod.rs

1//! Header metadata definitions
2
3use std::io::{Read, Seek, Write};
4
5pub mod data_extension_hdr;
6pub mod file_hdr;
7pub mod graphic_hdr;
8pub mod image_hdr;
9pub mod reserved_extension_hdr;
10pub mod text_hdr;
11
12pub use data_extension_hdr::DataExtensionHeader;
13pub use file_hdr::NitfHeader;
14pub use graphic_hdr::GraphicHeader;
15pub use image_hdr::ImageHeader;
16pub use reserved_extension_hdr::ReservedExtensionHeader;
17pub use text_hdr::TextHeader;
18
19use crate::NitfResult;
20
21/// Nitf segment header interface definition
22///
23/// Provide implementation for `read()`, `from_reader` defined automatically.
24pub trait NitfSegmentHeader
25where
26    Self: Sized + Default + PartialEq + Eq + Ord + PartialOrd + Clone,
27{
28    /// Read the segment info from stream
29    ///
30    /// # Parameters
31    ///
32    /// reader: Stream from which to read header information
33    #[allow(unused)]
34    fn read(&mut self, reader: &mut (impl Read + Seek)) -> NitfResult<()>;
35
36    /// Write the segment info to stream
37    ///
38    /// # Parameters
39    ///
40    /// writer: Stream from which to write header information
41    #[allow(unused)]
42    fn write(&self, writer: &mut (impl Write + Seek)) -> NitfResult<usize>;
43
44    /// Get the length of the segment
45    #[allow(unused)]
46    fn length(&self) -> usize;
47
48    fn from_reader(reader: &mut (impl Read + Seek)) -> NitfResult<Self> {
49        let mut hdr = Self::default();
50        hdr.read(reader)?;
51        Ok(hdr)
52    }
53}