rxing/oned/rss/expanded/decoders/
ai_01392x_decoder.rs1use crate::common::{BitArray, Result};
28
29use super::{AI01decoder, AbstractExpandedDecoder, GeneralAppIdDecoder};
30
31pub struct AI01392xDecoder<'a> {
35 information: &'a BitArray,
36 general_decoder: GeneralAppIdDecoder<'a>,
37}
38impl AI01decoder for AI01392xDecoder<'_> {}
39impl AbstractExpandedDecoder for AI01392xDecoder<'_> {
40 fn parseInformation(&mut self) -> Result<String> {
41 if self.information.get_size() < Self::HEADER_SIZE + Self::GTIN_SIZE as usize {
42 return Err(crate::Exceptions::NOT_FOUND);
43 }
44
45 let mut buf = String::new();
46
47 self.encodeCompressedGtin(&mut buf, Self::HEADER_SIZE);
48
49 let lastAIdigit = self.getGeneralDecoder().extractNumericValueFromBitArray(
50 Self::HEADER_SIZE + Self::GTIN_SIZE as usize,
51 Self::LAST_DIGIT_SIZE as u32,
52 );
53 buf.push_str("(392");
54 buf.push_str(&lastAIdigit.to_string());
55 buf.push(')');
56
57 let decodedInformation = self.general_decoder.decodeGeneralPurposeField(
58 Self::HEADER_SIZE + Self::GTIN_SIZE as usize + Self::LAST_DIGIT_SIZE,
59 "",
60 )?;
61 buf.push_str(decodedInformation.getNewString());
62
63 Ok(buf)
64 }
65
66 fn getGeneralDecoder(&'_ self) -> &'_ super::GeneralAppIdDecoder<'_> {
67 &self.general_decoder
68 }
69}
70impl<'a> AI01392xDecoder<'_> {
71 const HEADER_SIZE: usize = 5 + 1 + 2;
72 const LAST_DIGIT_SIZE: usize = 2;
73
74 pub fn new(information: &'a BitArray) -> AI01392xDecoder<'a> {
75 AI01392xDecoder {
76 information,
77 general_decoder: GeneralAppIdDecoder::new(information),
78 }
79 }
80}