rxing/oned/rss/expanded/decoders/
abstract_expanded_decoder.rs1use crate::{
28 common::{BitArray, Result},
29 Exceptions,
30};
31
32use super::{
33 AI013103decoder, AI01320xDecoder, AI01392xDecoder, AI01393xDecoder, AI013x0x1xDecoder,
34 AI01AndOtherAIs, AnyAIDecoder, GeneralAppIdDecoder,
35};
36
37pub trait AbstractExpandedDecoder {
43 fn parseInformation(&mut self) -> Result<String>;
60 fn getGeneralDecoder(&self) -> &GeneralAppIdDecoder<'_>;
61 }
63
64pub fn createDecoder<'a>(
65 information: &'a BitArray,
66) -> Result<Box<dyn AbstractExpandedDecoder + 'a>> {
67 if information.get(1) {
68 return Ok(Box::new(AI01AndOtherAIs::new(information)));
69 }
70 if !information.get(2) {
71 return Ok(Box::new(AnyAIDecoder::new(information)));
72 }
73
74 let fourBitEncodationMethod =
77 GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 4);
78
79 match fourBitEncodationMethod {
80 4 => return Ok(Box::new(AI013103decoder::new(information))),
81 5 => return Ok(Box::new(AI01320xDecoder::new(information))),
82 _ => {}
83 }
84
85 let fiveBitEncodationMethod =
86 GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 5);
87 match fiveBitEncodationMethod {
88 12 => return Ok(Box::new(AI01392xDecoder::new(information))),
89 13 => return Ok(Box::new(AI01393xDecoder::new(information))),
90 _ => {}
91 }
92
93 let sevenBitEncodationMethod =
94 GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 7);
95 match sevenBitEncodationMethod {
96 56 => return Ok(Box::new(AI013x0x1xDecoder::new(information, "310", "11"))),
97 57 => return Ok(Box::new(AI013x0x1xDecoder::new(information, "320", "11"))),
98 58 => return Ok(Box::new(AI013x0x1xDecoder::new(information, "310", "13"))),
99 59 => return Ok(Box::new(AI013x0x1xDecoder::new(information, "320", "13"))),
100 60 => return Ok(Box::new(AI013x0x1xDecoder::new(information, "310", "15"))),
101 61 => return Ok(Box::new(AI013x0x1xDecoder::new(information, "320", "15"))),
102 62 => return Ok(Box::new(AI013x0x1xDecoder::new(information, "310", "17"))),
103 63 => return Ok(Box::new(AI013x0x1xDecoder::new(information, "320", "17"))),
104 _ => {}
105 }
106
107 Err(Exceptions::illegal_state_with(format!(
108 "unknown decoder: {information}"
109 )))
110}