@@ -10,25 +10,25 @@ use std::io::{Read, Write};
1010use crate :: { error:: Result , HeaderError } ;
1111
1212/// Current magic number: "BSEQ" in ASCII (in little-endian byte order)
13- ///
13+ ///
1414/// This is used to identify binary sequence files and verify file integrity.
1515const MAGIC : u32 = 0x51455342 ;
1616
1717/// Current format version of the binary sequence file format
18- ///
18+ ///
1919/// This version number allows for future format changes while maintaining backward compatibility.
2020const FORMAT : u8 = 1 ;
2121
2222/// Size of the header in bytes
23- ///
23+ ///
2424/// The header has a fixed size to ensure consistent reading and writing of binary sequence files.
2525pub const SIZE_HEADER : usize = 32 ;
2626
2727/// Header structure for binary sequence files
28- ///
28+ ///
2929/// The `BinseqHeader` contains metadata about the binary sequence data stored in a file,
3030/// including format information, sequence lengths, and space for future extensions.
31- ///
31+ ///
3232/// The total size of this structure is 32 bytes, with a fixed layout to ensure
3333/// consistent reading and writing across different platforms.
3434#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
@@ -60,17 +60,17 @@ pub struct BinseqHeader {
6060}
6161impl BinseqHeader {
6262 /// Creates a new header with the specified sequence length
63- ///
63+ ///
6464 /// This constructor initializes a standard header with the given sequence length,
6565 /// setting the magic number and format version to their default values.
6666 /// The extended sequence length (xlen) is set to 0.
67- ///
67+ ///
6868 /// # Arguments
69- ///
69+ ///
7070 /// * `slen` - The length of sequences in the file
71- ///
71+ ///
7272 /// # Returns
73- ///
73+ ///
7474 /// A new `BinseqHeader` instance
7575 pub fn new ( slen : u32 ) -> Self {
7676 Self {
@@ -83,17 +83,17 @@ impl BinseqHeader {
8383 }
8484
8585 /// Creates a new header with both primary and extended sequence lengths
86- ///
86+ ///
8787 /// This constructor initializes a header for files that contain both primary
8888 /// and secondary sequence data, such as quality scores or annotations.
89- ///
89+ ///
9090 /// # Arguments
91- ///
91+ ///
9292 /// * `slen` - The length of primary sequences in the file
9393 /// * `xlen` - The length of secondary/extended sequences in the file
94- ///
94+ ///
9595 /// # Returns
96- ///
96+ ///
9797 /// A new `BinseqHeader` instance with extended sequence information
9898 pub fn new_extended ( slen : u32 , xlen : u32 ) -> Self {
9999 Self {
@@ -106,21 +106,21 @@ impl BinseqHeader {
106106 }
107107
108108 /// Parses a header from a fixed-size byte array
109- ///
109+ ///
110110 /// This method validates the magic number and format version before constructing
111111 /// a header instance. If validation fails, appropriate errors are returned.
112- ///
112+ ///
113113 /// # Arguments
114- ///
114+ ///
115115 /// * `buffer` - A byte array of exactly `SIZE_HEADER` bytes containing the header data
116- ///
116+ ///
117117 /// # Returns
118- ///
118+ ///
119119 /// * `Ok(BinseqHeader)` - A valid header parsed from the buffer
120120 /// * `Err(Error)` - If the buffer contains invalid header data
121- ///
121+ ///
122122 /// # Errors
123- ///
123+ ///
124124 /// Returns an error if:
125125 /// * The magic number is incorrect
126126 /// * The format version is unsupported
@@ -150,22 +150,22 @@ impl BinseqHeader {
150150 }
151151
152152 /// Parses a header from an arbitrarily sized buffer
153- ///
153+ ///
154154 /// This method extracts the header from the beginning of a buffer that may be larger
155155 /// than the header size. It checks that the buffer is at least as large as the header
156156 /// before attempting to parse it.
157- ///
157+ ///
158158 /// # Arguments
159- ///
159+ ///
160160 /// * `buffer` - A byte slice containing at least `SIZE_HEADER` bytes
161- ///
161+ ///
162162 /// # Returns
163- ///
163+ ///
164164 /// * `Ok(BinseqHeader)` - A valid header parsed from the buffer
165165 /// * `Err(Error)` - If the buffer is too small or contains invalid header data
166- ///
166+ ///
167167 /// # Errors
168- ///
168+ ///
169169 /// Returns an error if:
170170 /// * The buffer is smaller than `SIZE_HEADER`
171171 /// * The header data is invalid (see `from_bytes` for validation details)
@@ -179,21 +179,21 @@ impl BinseqHeader {
179179 }
180180
181181 /// Writes the header to a writer
182- ///
182+ ///
183183 /// This method serializes the header to its binary representation and writes it
184184 /// to the provided writer.
185- ///
185+ ///
186186 /// # Arguments
187- ///
187+ ///
188188 /// * `writer` - Any type that implements the `Write` trait
189- ///
189+ ///
190190 /// # Returns
191- ///
191+ ///
192192 /// * `Ok(())` - If the header was successfully written
193193 /// * `Err(Error)` - If writing to the writer failed
194- ///
194+ ///
195195 /// # Errors
196- ///
196+ ///
197197 /// Returns an error if writing to the writer fails (typically an I/O error).
198198 pub fn write_bytes < W : Write > ( & self , writer : & mut W ) -> Result < ( ) > {
199199 let mut buffer = [ 0u8 ; SIZE_HEADER ] ;
@@ -207,21 +207,21 @@ impl BinseqHeader {
207207 }
208208
209209 /// Reads a header from a reader
210- ///
210+ ///
211211 /// This method reads exactly `SIZE_HEADER` bytes from the provided reader and
212212 /// parses them into a header structure.
213- ///
213+ ///
214214 /// # Arguments
215- ///
215+ ///
216216 /// * `reader` - Any type that implements the `Read` trait
217- ///
217+ ///
218218 /// # Returns
219- ///
219+ ///
220220 /// * `Ok(BinseqHeader)` - A valid header read from the reader
221221 /// * `Err(Error)` - If reading from the reader failed or the header data is invalid
222- ///
222+ ///
223223 /// # Errors
224- ///
224+ ///
225225 /// Returns an error if:
226226 /// * Reading from the reader fails (typically an I/O error)
227227 /// * The header data is invalid (see `from_bytes` for validation details)
0 commit comments