rxing/oned/rss/expanded/decoders/
abstract_expanded_decoder.rs

1/*
2 * Copyright (C) 2010 ZXing authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * These authors would like to acknowledge the Spanish Ministry of Industry,
19 * Tourism and Trade, for the support in the project TSI020301-2008-2
20 * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 * Mobile Dynamic Environments", led by Treelogic
22 * ( http://www.treelogic.com/ ):
23 *
24 *   http://www.piramidepse.com/
25 */
26
27use crate::{
28    common::{BitArray, Result},
29    Exceptions,
30};
31
32use super::{
33    AI013103decoder, AI01320xDecoder, AI01392xDecoder, AI01393xDecoder, AI013x0x1xDecoder,
34    AI01AndOtherAIs, AnyAIDecoder, GeneralAppIdDecoder,
35};
36
37/*
38 * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
39 * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
40 */
41
42pub trait AbstractExpandedDecoder {
43    // private final BitArray information;
44    // private final GeneralAppIdDecoder generalDecoder;
45
46    // AbstractExpandedDecoder(BitArray information) {
47    //   this.information = information;
48    //   this.generalDecoder = new GeneralAppIdDecoder(information);
49    // }
50
51    // protected final BitArray getInformation() {
52    //   return information;
53    // }
54
55    // protected final GeneralAppIdDecoder getGeneralDecoder() {
56    //   return generalDecoder;
57    // }
58
59    fn parseInformation(&mut self) -> Result<String>;
60    fn getGeneralDecoder(&self) -> &GeneralAppIdDecoder<'_>;
61    // fn new(information:&BitArray) -> Self where Self:Sized;
62}
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 gen_decode = GeneralAppIdDecoder::new(information);
75
76    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}