From 69cdeb4417604781376f6ad87b149265c2a602a3 Mon Sep 17 00:00:00 2001 From: Hunter Trujillo Date: Fri, 1 Sep 2023 15:31:55 -0600 Subject: [PATCH] Refactor magic number to more compact format. --- src/constants.rs | 4 +--- src/file.rs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index 2731c33..aec9024 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -2,9 +2,7 @@ use bitmask_enum::bitmask; use serde::{Deserialize, Serialize}; /// "Magic number" used by the Carbonado file format. 12 bytes: "CARBONADO", and a version, 00, plus a newline character -pub const MAGICNO: [u8; 12] = [ - b'C', b'A', b'R', b'B', b'O', b'N', b'A', b'D', b'O', b'0', b'0', b'\n', -]; +pub const MAGICNO: &[u8; 12] = b"CARBONADO00\n"; /// Bao slice length pub const SLICE_LEN: u16 = 1024; diff --git a/src/file.rs b/src/file.rs index d59aca0..1a90622 100644 --- a/src/file.rs +++ b/src/file.rs @@ -70,7 +70,7 @@ impl TryFrom<&File> for Header { handle.read_exact(&mut padding_len)?; handle.read_exact(&mut metadata)?; - if magic_no != MAGICNO { + if &magic_no != MAGICNO { return Err(CarbonadoError::InvalidMagicNumber(format!("{magic_no:#?}"))); }