continue removing todo!()s

This commit is contained in:
Henry Schimke
2023-03-28 16:31:41 -05:00
parent 607bb28101
commit 74a459f65a
5 changed files with 76 additions and 25 deletions

View File

@@ -66,7 +66,7 @@ impl Version {
return Err(Exceptions::ILLEGAL_STATE); return Err(Exceptions::ILLEGAL_STATE);
} }
pub fn isMicroQRCode(&self) -> bool { pub const fn isMicroQRCode(&self) -> bool {
self.is_micro self.is_micro
} }
} }

View File

@@ -47,12 +47,14 @@ where
Self::default() Self::default()
} }
pub fn with_eci_string_builder(src: ECIStringBuilder) -> Self { pub fn with_eci_string_builder(src: ECIStringBuilder) -> Self {
todo!() let mut new_self = Self::default();
new_self.content = src;
new_self
} }
pub fn isValid(&self) -> bool { pub fn isValid(&self) -> bool {
self.content.symbology.code != 0
//return includeErrors || (_content.symbology.code != 0 && !_error); //return includeErrors || (_content.symbology.code != 0 && !_error);
todo!()
} }
pub fn content(&self) -> &ECIStringBuilder { pub fn content(&self) -> &ECIStringBuilder {

View File

@@ -306,7 +306,7 @@ pub fn DecodeBitStream(
mode = Mode::CodecModeForBits( mode = Mode::CodecModeForBits(
bits.readBits(modeBitLength as usize)?, bits.readBits(modeBitLength as usize)?,
Some(version.isMicroQRCode()), Some(version.isMicroQRCode()),
); )?;
} }
match (mode) { match (mode) {

View File

@@ -123,10 +123,18 @@ impl Mode {
} }
pub const fn get_terminator_bit_length(version: &Version) -> u8 { pub const fn get_terminator_bit_length(version: &Version) -> u8 {
todo!() (if version.isMicroQRCode() {
version.getVersionNumber() * 2 + 1
} else {
4
}) as u8
} }
pub const fn get_codec_mode_bits_length(version: &Version) -> u8 { pub const fn get_codec_mode_bits_length(version: &Version) -> u8 {
todo!() (if version.isMicroQRCode() {
version.getVersionNumber() - 1
} else {
4
}) as u8
} }
/** /**
* @param bits variable number of bits encoding a QR Code data mode * @param bits variable number of bits encoding a QR Code data mode
@@ -134,9 +142,23 @@ impl Mode {
* @return Mode encoded by these bits * @return Mode encoded by these bits
* @throws FormatError if bits do not correspond to a known mode * @throws FormatError if bits do not correspond to a known mode
*/ */
pub fn CodecModeForBits(bits: u32, isMicro: Option<bool>) -> Self { pub fn CodecModeForBits(bits: u32, isMicro: Option<bool>) -> Result<Self> {
let isMicro = isMicro.unwrap_or(false); let isMicro = isMicro.unwrap_or(false);
todo!() const BITS_2_MODE_LEN: usize = 4;
if (!isMicro) {
if ((bits >= 0x00 && bits <= 0x05) || (bits >= 0x07 && bits <= 0x09) || bits == 0x0d) {
return Mode::try_from(bits);
}
} else {
const Bits2Mode: [Mode; BITS_2_MODE_LEN] =
[Mode::NUMERIC, Mode::ALPHANUMERIC, Mode::BYTE, Mode::KANJI];
if ((bits as usize) < BITS_2_MODE_LEN) {
return Ok(Bits2Mode[bits as usize]);
}
}
Err(Exceptions::format_with("Invalid codec mode"))
} }
/** /**
@@ -162,3 +184,11 @@ impl TryFrom<u8> for Mode {
Self::forBits(value) Self::forBits(value)
} }
} }
impl TryFrom<u32> for Mode {
type Error = Exceptions;
fn try_from(value: u32) -> Result<Self, Self::Error> {
Self::forBits(value as u8)
}
}

View File

@@ -72,7 +72,7 @@ impl Version {
alignmentPatternCenters, alignmentPatternCenters,
ecBlocks: ecBlocks.to_vec(), ecBlocks: ecBlocks.to_vec(),
totalCodewords: total, totalCodewords: total,
is_micro: false is_micro: false,
} }
} }
@@ -91,11 +91,11 @@ impl Version {
alignmentPatternCenters: Vec::default(), alignmentPatternCenters: Vec::default(),
ecBlocks, ecBlocks,
totalCodewords: total, totalCodewords: total,
is_micro: true is_micro: true,
} }
} }
pub fn getVersionNumber(&self) -> u32 { pub const fn getVersionNumber(&self) -> u32 {
self.versionNumber self.versionNumber
} }
@@ -206,9 +206,28 @@ impl Version {
pub fn build_micro_versions() -> Vec<Version> { pub fn build_micro_versions() -> Vec<Version> {
vec![ vec![
Version::new_micro(1, vec![ECBlocks::new(2, vec![ECB::new(1, 3)])]), Version::new_micro(1, vec![ECBlocks::new(2, vec![ECB::new(1, 3)])]),
Version::new_micro(2, vec![ECBlocks::new(5, vec![ECB::new(1,5)]), ECBlocks::new(6, vec![ECB::new(1,4)])]), Version::new_micro(
Version::new_micro(3, vec![ECBlocks::new(6, vec![ECB::new(1,11)]), ECBlocks::new(8, vec![ECB::new(1,9)])]), 2,
Version::new_micro(4, vec![ECBlocks::new(8, vec![ECB::new(1,16)]), ECBlocks::new(10, vec![ECB::new(1,14)]), ECBlocks::new(14, vec![ECB::new(1,10)])]), vec![
ECBlocks::new(5, vec![ECB::new(1, 5)]),
ECBlocks::new(6, vec![ECB::new(1, 4)]),
],
),
Version::new_micro(
3,
vec![
ECBlocks::new(6, vec![ECB::new(1, 11)]),
ECBlocks::new(8, vec![ECB::new(1, 9)]),
],
),
Version::new_micro(
4,
vec![
ECBlocks::new(8, vec![ECB::new(1, 16)]),
ECBlocks::new(10, vec![ECB::new(1, 14)]),
ECBlocks::new(14, vec![ECB::new(1, 10)]),
],
),
] ]
// static const Version allVersions[] = { // static const Version allVersions[] = {
// {1, {2, 1, 3, 0, 0}}, // {1, {2, 1, 3, 0, 0}},