1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! CRAM file definition and fields.

mod version;

pub use self::version::Version;

/// A CRAM file definition.
///
/// The CRAM file definition holds the format version and file ID. See ยง 6 File definition
/// (2020-06-22).
#[derive(Clone, Default, Debug, Eq, PartialEq)]
pub struct FileDefinition {
    version: Version,
    file_id: [u8; 20],
}

impl FileDefinition {
    /// Creates a file definition.
    ///
    /// # Examples
    ///
    /// ```
    /// use noodles_cram::{file_definition::Version, FileDefinition};
    /// let file_definition = FileDefinition::new(Version::new(3, 0), [0; 20]);
    /// ```
    pub fn new(version: Version, file_id: [u8; 20]) -> Self {
        Self { version, file_id }
    }

    /// Returns the file version.
    ///
    /// This is also called the (major and minor) format number.
    ///
    /// # Examples
    ///
    /// ```
    /// use noodles_cram::{file_definition::Version, FileDefinition};
    /// let file_definition = FileDefinition::new(Version::new(3, 0), [0; 20]);
    /// assert_eq!(file_definition.version(), Version::new(3, 0));
    /// ```
    pub fn version(&self) -> Version {
        self.version
    }

    /// Returns the file ID.
    ///
    /// The file ID has a fixed length of 20 bytes. It can be any arbitrary identifier, e.g., the
    /// file name or a 160-bit checksum.
    ///
    /// # Examples
    ///
    /// ```
    /// use noodles_cram::{file_definition::Version, FileDefinition};
    /// let file_definition = FileDefinition::new(Version::new(3, 0), [0; 20]);
    /// assert_eq!(file_definition.file_id(), [0; 20]);
    /// ```
    pub fn file_id(&self) -> &[u8] {
        &self.file_id
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_default() {
        let actual = FileDefinition::default();
        let expected = FileDefinition::new(Version::new(3, 0), [0; 20]);
        assert_eq!(actual, expected);
    }
}