mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 04:42:35 +00:00
cargo fmt
This commit is contained in:
@@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2010 ZXing authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.zxing.oned.rss.expanded;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* One row of an RSS Expanded Stacked symbol, consisting of 1+ expanded pairs.
|
|
||||||
*/
|
|
||||||
final class ExpandedRow {
|
|
||||||
|
|
||||||
private final List<ExpandedPair> pairs;
|
|
||||||
private final int rowNumber;
|
|
||||||
|
|
||||||
ExpandedRow(List<ExpandedPair> pairs, int rowNumber) {
|
|
||||||
this.pairs = new ArrayList<>(pairs);
|
|
||||||
this.rowNumber = rowNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ExpandedPair> getPairs() {
|
|
||||||
return this.pairs;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getRowNumber() {
|
|
||||||
return this.rowNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isEquivalent(List<ExpandedPair> otherPairs) {
|
|
||||||
return this.pairs.equals(otherPairs);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "{ " + pairs + " }";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Two rows are equal if they contain the same pairs in the same order.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (!(o instanceof ExpandedRow)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ExpandedRow that = (ExpandedRow) o;
|
|
||||||
return this.pairs.equals(that.pairs);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return pairs.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -24,7 +24,10 @@
|
|||||||
* http://www.piramidepse.com/
|
* http://www.piramidepse.com/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::oned::rss::expanded::{binary_util, decoders::{AbstractExpandedDecoder, abstract_expanded_decoder::createDecoder}};
|
use crate::oned::rss::expanded::{
|
||||||
|
binary_util,
|
||||||
|
decoders::{abstract_expanded_decoder::createDecoder, AbstractExpandedDecoder},
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||||
@@ -33,7 +36,7 @@ use crate::oned::rss::expanded::{binary_util, decoders::{AbstractExpandedDecoder
|
|||||||
pub const numeric10: &str = "..X..XX";
|
pub const numeric10: &str = "..X..XX";
|
||||||
pub const numeric12: &str = "..X.X.X";
|
pub const numeric12: &str = "..X.X.X";
|
||||||
pub const numeric1FNC1: &str = "..XXX.X";
|
pub const numeric1FNC1: &str = "..XXX.X";
|
||||||
// static final String numericFNC11 = "XXX.XXX";
|
// static final String numericFNC11 = "XXX.XXX";
|
||||||
|
|
||||||
pub const numeric2alpha: &str = "....";
|
pub const numeric2alpha: &str = "....";
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,10 @@
|
|||||||
|
|
||||||
use crate::{common::BitArray, Exceptions};
|
use crate::{common::BitArray, Exceptions};
|
||||||
|
|
||||||
use super::{GeneralAppIdDecoder, AnyAIDecoder, AI01AndOtherAIs, AI013103decoder, AI01320xDecoder, AI01392xDecoder, AI01393xDecoder, AI013x0x1xDecoder};
|
use super::{
|
||||||
|
AI013103decoder, AI01320xDecoder, AI01392xDecoder, AI01393xDecoder, AI013x0x1xDecoder,
|
||||||
|
AI01AndOtherAIs, AnyAIDecoder, GeneralAppIdDecoder,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||||
@@ -55,43 +58,99 @@ pub trait AbstractExpandedDecoder {
|
|||||||
// fn new(information:&BitArray) -> Self where Self:Sized;
|
// fn new(information:&BitArray) -> Self where Self:Sized;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn createDecoder<'a>( information:&'a BitArray) -> Result<Box<dyn AbstractExpandedDecoder + 'a>,Exceptions>{
|
pub fn createDecoder<'a>(
|
||||||
if information.get(1) {
|
information: &'a BitArray,
|
||||||
return Ok(Box::new(AI01AndOtherAIs::new(information)))
|
) -> Result<Box<dyn AbstractExpandedDecoder + 'a>, Exceptions> {
|
||||||
}
|
if information.get(1) {
|
||||||
if !information.get(2) {
|
return Ok(Box::new(AI01AndOtherAIs::new(information)));
|
||||||
return Ok(Box::new( AnyAIDecoder::new(information)));
|
}
|
||||||
}
|
if !information.get(2) {
|
||||||
|
return Ok(Box::new(AnyAIDecoder::new(information)));
|
||||||
|
}
|
||||||
|
|
||||||
// let gen_decode = GeneralAppIdDecoder::new(information);
|
// let gen_decode = GeneralAppIdDecoder::new(information);
|
||||||
|
|
||||||
let fourBitEncodationMethod = GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 4);
|
let fourBitEncodationMethod =
|
||||||
|
GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 4);
|
||||||
|
|
||||||
match fourBitEncodationMethod {
|
match fourBitEncodationMethod {
|
||||||
4=> return Ok(Box::new( AI013103decoder::new(information))),
|
4 => return Ok(Box::new(AI013103decoder::new(information))),
|
||||||
5=> return Ok(Box::new( AI01320xDecoder::new(information))),
|
5 => return Ok(Box::new(AI01320xDecoder::new(information))),
|
||||||
_=>{},
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
let fiveBitEncodationMethod = GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 5);
|
let fiveBitEncodationMethod =
|
||||||
match fiveBitEncodationMethod {
|
GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 5);
|
||||||
12=> return Ok(Box::new( AI01392xDecoder::new(information))),
|
match fiveBitEncodationMethod {
|
||||||
13=> return Ok(Box::new( AI01393xDecoder::new(information))),
|
12 => return Ok(Box::new(AI01392xDecoder::new(information))),
|
||||||
_=>{},
|
13 => return Ok(Box::new(AI01393xDecoder::new(information))),
|
||||||
}
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
let sevenBitEncodationMethod = GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 7);
|
let sevenBitEncodationMethod =
|
||||||
match sevenBitEncodationMethod {
|
GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 7);
|
||||||
56=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "310".to_owned(), "11".to_owned()))),
|
match sevenBitEncodationMethod {
|
||||||
57=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "320".to_owned(), "11".to_owned()))),
|
56 => {
|
||||||
58=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "310".to_owned(), "13".to_owned()))),
|
return Ok(Box::new(AI013x0x1xDecoder::new(
|
||||||
59=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "320".to_owned(), "13".to_owned()))),
|
information,
|
||||||
60=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "310".to_owned(), "15".to_owned()))),
|
"310".to_owned(),
|
||||||
61=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "320".to_owned(), "15".to_owned()))),
|
"11".to_owned(),
|
||||||
62=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "310".to_owned(), "17".to_owned()))),
|
)))
|
||||||
63=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "320".to_owned(), "17".to_owned()))),
|
}
|
||||||
_=>{},
|
57 => {
|
||||||
}
|
return Ok(Box::new(AI013x0x1xDecoder::new(
|
||||||
|
information,
|
||||||
|
"320".to_owned(),
|
||||||
|
"11".to_owned(),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
58 => {
|
||||||
|
return Ok(Box::new(AI013x0x1xDecoder::new(
|
||||||
|
information,
|
||||||
|
"310".to_owned(),
|
||||||
|
"13".to_owned(),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
59 => {
|
||||||
|
return Ok(Box::new(AI013x0x1xDecoder::new(
|
||||||
|
information,
|
||||||
|
"320".to_owned(),
|
||||||
|
"13".to_owned(),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
60 => {
|
||||||
|
return Ok(Box::new(AI013x0x1xDecoder::new(
|
||||||
|
information,
|
||||||
|
"310".to_owned(),
|
||||||
|
"15".to_owned(),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
61 => {
|
||||||
|
return Ok(Box::new(AI013x0x1xDecoder::new(
|
||||||
|
information,
|
||||||
|
"320".to_owned(),
|
||||||
|
"15".to_owned(),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
62 => {
|
||||||
|
return Ok(Box::new(AI013x0x1xDecoder::new(
|
||||||
|
information,
|
||||||
|
"310".to_owned(),
|
||||||
|
"17".to_owned(),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
63 => {
|
||||||
|
return Ok(Box::new(AI013x0x1xDecoder::new(
|
||||||
|
information,
|
||||||
|
"320".to_owned(),
|
||||||
|
"17".to_owned(),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
Err(Exceptions::IllegalStateException(format!("unknown decoder: {}" , information)))
|
Err(Exceptions::IllegalStateException(format!(
|
||||||
|
"unknown decoder: {}",
|
||||||
|
information
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,48 +55,58 @@ impl AI01decoder for AI013103decoder<'_> {}
|
|||||||
|
|
||||||
impl<'a> AI013103decoder<'_> {
|
impl<'a> AI013103decoder<'_> {
|
||||||
pub fn new(information: &'a BitArray) -> AI013103decoder<'a> {
|
pub fn new(information: &'a BitArray) -> AI013103decoder<'a> {
|
||||||
AI013103decoder(AI013x0xDecoder::new(information, addWeightCode, checkWeight))
|
AI013103decoder(AI013x0xDecoder::new(
|
||||||
|
information,
|
||||||
|
addWeightCode,
|
||||||
|
checkWeight,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn addWeightCode( buf: &mut String, _weight: u32) {
|
fn addWeightCode(buf: &mut String, _weight: u32) {
|
||||||
buf.push_str("(3103)");
|
buf.push_str("(3103)");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn checkWeight( weight: u32) -> u32 {
|
fn checkWeight(weight: u32) -> u32 {
|
||||||
weight
|
weight
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||||
*/
|
*/
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod AI013103DecoderTest {
|
mod AI013103DecoderTest {
|
||||||
use crate::oned::rss::expanded::decoders::abstract_decoder_test_utils::*;
|
use crate::oned::rss::expanded::decoders::abstract_decoder_test_utils::*;
|
||||||
|
|
||||||
|
const header: &str = "..X..";
|
||||||
const header :&str = "..X..";
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test0131031() {
|
fn test0131031() {
|
||||||
let data = format!("{}{}{}", header , compressedGtin900123456798908 , compressed15bitWeight1750);
|
let data = format!(
|
||||||
let expected = "(01)90012345678908(3103)001750";
|
"{}{}{}",
|
||||||
assertCorrectBinaryString(&data, expected);
|
header, compressedGtin900123456798908, compressed15bitWeight1750
|
||||||
|
);
|
||||||
|
let expected = "(01)90012345678908(3103)001750";
|
||||||
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test0131032() {
|
fn test0131032() {
|
||||||
let data = format!("{}{}{}",header , compressedGtin900000000000008 , compressed15bitWeight0);
|
let data = format!(
|
||||||
let expected = "(01)90000000000003(3103)000000";
|
"{}{}{}",
|
||||||
assertCorrectBinaryString(&data, expected);
|
header, compressedGtin900000000000008, compressed15bitWeight0
|
||||||
|
);
|
||||||
|
let expected = "(01)90000000000003(3103)000000";
|
||||||
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test013103invalid() {
|
fn test013103invalid() {
|
||||||
let data = format!("{}{}{}..",header , compressedGtin900123456798908 , compressed15bitWeight1750 );
|
let data = format!(
|
||||||
assertCorrectBinaryString(&data, "");
|
"{}{}{}..",
|
||||||
|
header, compressedGtin900123456798908, compressed15bitWeight1750
|
||||||
|
);
|
||||||
|
assertCorrectBinaryString(&data, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,29 +26,30 @@
|
|||||||
|
|
||||||
use super::abstract_decoder_test_utils::*;
|
use super::abstract_decoder_test_utils::*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const header: &str = "..X.X";
|
||||||
|
|
||||||
const header :&str = "..X.X";
|
#[test]
|
||||||
|
fn test0132021() {
|
||||||
#[test]
|
let data = format!(
|
||||||
fn test0132021() {
|
"{}{}{}",
|
||||||
let data = format!("{}{}{}",header, compressedGtin900123456798908 , compressed15bitWeight1750);
|
header, compressedGtin900123456798908, compressed15bitWeight1750
|
||||||
|
);
|
||||||
let expected = "(01)90012345678908(3202)001750";
|
let expected = "(01)90012345678908(3202)001750";
|
||||||
|
|
||||||
assertCorrectBinaryString(&data, expected);
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test0132031() {
|
fn test0132031() {
|
||||||
let data = format!("{}{}{}",header , compressedGtin900123456798908 , compressed15bitWeight11750);
|
let data = format!(
|
||||||
|
"{}{}{}",
|
||||||
|
header, compressedGtin900123456798908, compressed15bitWeight11750
|
||||||
|
);
|
||||||
let expected = "(01)90012345678908(3203)001750";
|
let expected = "(01)90012345678908(3203)001750";
|
||||||
|
|
||||||
assertCorrectBinaryString(&data, expected);
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,11 @@ impl AbstractExpandedDecoder for AI01320xDecoder<'_> {
|
|||||||
impl AI01decoder for AI01320xDecoder<'_> {}
|
impl AI01decoder for AI01320xDecoder<'_> {}
|
||||||
impl<'a> AI01320xDecoder<'_> {
|
impl<'a> AI01320xDecoder<'_> {
|
||||||
pub fn new(information: &'a BitArray) -> AI01320xDecoder<'a> {
|
pub fn new(information: &'a BitArray) -> AI01320xDecoder<'a> {
|
||||||
AI01320xDecoder(AI013x0xDecoder::new(information, addWeightCode, checkWeight))
|
AI01320xDecoder(AI013x0xDecoder::new(
|
||||||
|
information,
|
||||||
|
addWeightCode,
|
||||||
|
checkWeight,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +70,7 @@ fn addWeightCode(buf: &mut String, weight: u32) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn checkWeight( weight: u32) -> u32 {
|
fn checkWeight(weight: u32) -> u32 {
|
||||||
if weight < 10000 {
|
if weight < 10000 {
|
||||||
weight
|
weight
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -132,103 +132,145 @@ impl<'a> AI013x0x1xDecoder<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||||
*/
|
*/
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod AI013X0X1XDecoderTest {
|
mod AI013X0X1XDecoderTest {
|
||||||
use crate::oned::rss::expanded::decoders::abstract_decoder_test_utils::*;
|
use crate::oned::rss::expanded::decoders::abstract_decoder_test_utils::*;
|
||||||
|
|
||||||
|
const header310x11: &str = "..XXX...";
|
||||||
const header310x11 : &str = "..XXX...";
|
const header320x11: &str = "..XXX..X";
|
||||||
const header320x11 : &str = "..XXX..X";
|
const header310x13: &str = "..XXX.X.";
|
||||||
const header310x13 : &str = "..XXX.X.";
|
const header320x13: &str = "..XXX.XX";
|
||||||
const header320x13 : &str = "..XXX.XX";
|
const header310x15: &str = "..XXXX..";
|
||||||
const header310x15 : &str = "..XXXX..";
|
const header320x15: &str = "..XXXX.X";
|
||||||
const header320x15 : &str = "..XXXX.X";
|
const header310x17: &str = "..XXXXX.";
|
||||||
const header310x17 : &str = "..XXXXX.";
|
const header320x17: &str = "..XXXXXX";
|
||||||
const header320x17 : &str = "..XXXXXX";
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test01310X1XendDate() {
|
fn test01310X1XendDate() {
|
||||||
let data = format!("{}{}{}{}", header310x11 , compressedGtin900123456798908 , compressed20bitWeight1750 , compressedDateEnd);
|
let data = format!(
|
||||||
let expected = "(01)90012345678908(3100)001750";
|
"{}{}{}{}",
|
||||||
|
header310x11,
|
||||||
|
compressedGtin900123456798908,
|
||||||
|
compressed20bitWeight1750,
|
||||||
|
compressedDateEnd
|
||||||
|
);
|
||||||
|
let expected = "(01)90012345678908(3100)001750";
|
||||||
|
|
||||||
assertCorrectBinaryString(&data, expected);
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test01310X111() {
|
fn test01310X111() {
|
||||||
let data = format!("{}{}{}{}", header310x11 , compressedGtin900123456798908 , compressed20bitWeight1750 ,
|
let data = format!(
|
||||||
compressedDateMarch12th2010);
|
"{}{}{}{}",
|
||||||
let expected = "(01)90012345678908(3100)001750(11)100312";
|
header310x11,
|
||||||
|
compressedGtin900123456798908,
|
||||||
|
compressed20bitWeight1750,
|
||||||
|
compressedDateMarch12th2010
|
||||||
|
);
|
||||||
|
let expected = "(01)90012345678908(3100)001750(11)100312";
|
||||||
|
|
||||||
assertCorrectBinaryString(&data, expected);
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test01320X111() {
|
fn test01320X111() {
|
||||||
let data = format!("{}{}{}{}",header320x11 , compressedGtin900123456798908 , compressed20bitWeight1750 ,
|
let data = format!(
|
||||||
compressedDateMarch12th2010);
|
"{}{}{}{}",
|
||||||
let expected = "(01)90012345678908(3200)001750(11)100312";
|
header320x11,
|
||||||
|
compressedGtin900123456798908,
|
||||||
|
compressed20bitWeight1750,
|
||||||
|
compressedDateMarch12th2010
|
||||||
|
);
|
||||||
|
let expected = "(01)90012345678908(3200)001750(11)100312";
|
||||||
|
|
||||||
assertCorrectBinaryString(&data, expected);
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test01310X131() {
|
fn test01310X131() {
|
||||||
let data = format!("{}{}{}{}", header310x13 , compressedGtin900123456798908 , compressed20bitWeight1750 ,
|
let data = format!(
|
||||||
compressedDateMarch12th2010);
|
"{}{}{}{}",
|
||||||
let expected = "(01)90012345678908(3100)001750(13)100312";
|
header310x13,
|
||||||
|
compressedGtin900123456798908,
|
||||||
|
compressed20bitWeight1750,
|
||||||
|
compressedDateMarch12th2010
|
||||||
|
);
|
||||||
|
let expected = "(01)90012345678908(3100)001750(13)100312";
|
||||||
|
|
||||||
assertCorrectBinaryString(&data, expected);
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test01320X131() {
|
fn test01320X131() {
|
||||||
let data = format!("{}{}{}{}", header320x13 , compressedGtin900123456798908 , compressed20bitWeight1750 ,
|
let data = format!(
|
||||||
compressedDateMarch12th2010);
|
"{}{}{}{}",
|
||||||
let expected = "(01)90012345678908(3200)001750(13)100312";
|
header320x13,
|
||||||
|
compressedGtin900123456798908,
|
||||||
|
compressed20bitWeight1750,
|
||||||
|
compressedDateMarch12th2010
|
||||||
|
);
|
||||||
|
let expected = "(01)90012345678908(3200)001750(13)100312";
|
||||||
|
|
||||||
assertCorrectBinaryString(&data, expected);
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test01310X151() {
|
fn test01310X151() {
|
||||||
let data = format!("{}{}{}{}", header310x15 , compressedGtin900123456798908 , compressed20bitWeight1750 ,
|
let data = format!(
|
||||||
compressedDateMarch12th2010);
|
"{}{}{}{}",
|
||||||
let expected = "(01)90012345678908(3100)001750(15)100312";
|
header310x15,
|
||||||
|
compressedGtin900123456798908,
|
||||||
|
compressed20bitWeight1750,
|
||||||
|
compressedDateMarch12th2010
|
||||||
|
);
|
||||||
|
let expected = "(01)90012345678908(3100)001750(15)100312";
|
||||||
|
|
||||||
assertCorrectBinaryString(&data, expected);
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test01320X151() {
|
fn test01320X151() {
|
||||||
let data = format!("{}{}{}{}", header320x15 , compressedGtin900123456798908 , compressed20bitWeight1750 ,
|
let data = format!(
|
||||||
compressedDateMarch12th2010);
|
"{}{}{}{}",
|
||||||
let expected = "(01)90012345678908(3200)001750(15)100312";
|
header320x15,
|
||||||
|
compressedGtin900123456798908,
|
||||||
|
compressed20bitWeight1750,
|
||||||
|
compressedDateMarch12th2010
|
||||||
|
);
|
||||||
|
let expected = "(01)90012345678908(3200)001750(15)100312";
|
||||||
|
|
||||||
assertCorrectBinaryString(&data, expected);
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test01310X171() {
|
fn test01310X171() {
|
||||||
let data = format!("{}{}{}{}", header310x17 , compressedGtin900123456798908 , compressed20bitWeight1750 ,
|
let data = format!(
|
||||||
compressedDateMarch12th2010);
|
"{}{}{}{}",
|
||||||
let expected = "(01)90012345678908(3100)001750(17)100312";
|
header310x17,
|
||||||
|
compressedGtin900123456798908,
|
||||||
|
compressed20bitWeight1750,
|
||||||
|
compressedDateMarch12th2010
|
||||||
|
);
|
||||||
|
let expected = "(01)90012345678908(3100)001750(17)100312";
|
||||||
|
|
||||||
assertCorrectBinaryString(&data, expected);
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test01320X171() {
|
fn test01320X171() {
|
||||||
let data = format!("{}{}{}{}", header320x17 , compressedGtin900123456798908 , compressed20bitWeight1750 ,
|
let data = format!(
|
||||||
compressedDateMarch12th2010);
|
"{}{}{}{}",
|
||||||
let expected = "(01)90012345678908(3200)001750(17)100312";
|
header320x17,
|
||||||
|
compressedGtin900123456798908,
|
||||||
|
compressed20bitWeight1750,
|
||||||
|
compressedDateMarch12th2010
|
||||||
|
);
|
||||||
|
let expected = "(01)90012345678908(3200)001750(17)100312";
|
||||||
|
|
||||||
assertCorrectBinaryString(&data, expected);
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -78,8 +78,11 @@ impl<'a> AI013x0xDecoder<'_> {
|
|||||||
const HEADER_SIZE: usize = 4 + 1;
|
const HEADER_SIZE: usize = 4 + 1;
|
||||||
const WEIGHT_SIZE: usize = 15;
|
const WEIGHT_SIZE: usize = 15;
|
||||||
|
|
||||||
pub fn new(information: &'a BitArray, addWeightCodeFunction: fn(&mut String, u32),
|
pub fn new(
|
||||||
checkWeightFunction: fn(u32) -> u32,) -> AI013x0xDecoder<'a> {
|
information: &'a BitArray,
|
||||||
|
addWeightCodeFunction: fn(&mut String, u32),
|
||||||
|
checkWeightFunction: fn(u32) -> u32,
|
||||||
|
) -> AI013x0xDecoder<'a> {
|
||||||
AI013x0xDecoder {
|
AI013x0xDecoder {
|
||||||
information,
|
information,
|
||||||
decoder: GeneralAppIdDecoder::new(information),
|
decoder: GeneralAppIdDecoder::new(information),
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ impl<'a> AnyAIDecoder<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||||
*/
|
*/
|
||||||
@@ -66,56 +65,77 @@ impl<'a> AnyAIDecoder<'_> {
|
|||||||
mod AnyAIDecoderTest {
|
mod AnyAIDecoderTest {
|
||||||
use crate::oned::rss::expanded::decoders::abstract_decoder_test_utils::*;
|
use crate::oned::rss::expanded::decoders::abstract_decoder_test_utils::*;
|
||||||
|
|
||||||
|
const HEADER: &str = ".....";
|
||||||
const HEADER : &str = ".....";
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn testAnyAIDecoder1() {
|
fn testAnyAIDecoder1() {
|
||||||
let data =format!("{}{}{}{}{}{}{}", HEADER , numeric10 , numeric12 , numeric2alpha , alphaA , alpha2numeric , numeric12);
|
let data = format!(
|
||||||
let expected = "(10)12A12";
|
"{}{}{}{}{}{}{}",
|
||||||
|
HEADER, numeric10, numeric12, numeric2alpha, alphaA, alpha2numeric, numeric12
|
||||||
|
);
|
||||||
|
let expected = "(10)12A12";
|
||||||
|
|
||||||
assertCorrectBinaryString(&data, expected);
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn testAnyAIDecoder2() {
|
fn testAnyAIDecoder2() {
|
||||||
let data =format!("{}{}{}{}{}{}{}", HEADER , numeric10 , numeric12 , numeric2alpha , alphaA , alpha2isoiec646 , i646B);
|
let data = format!(
|
||||||
let expected = "(10)12AB";
|
"{}{}{}{}{}{}{}",
|
||||||
|
HEADER, numeric10, numeric12, numeric2alpha, alphaA, alpha2isoiec646, i646B
|
||||||
|
);
|
||||||
|
let expected = "(10)12AB";
|
||||||
|
|
||||||
assertCorrectBinaryString(&data, expected);
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn testAnyAIDecoder3() {
|
fn testAnyAIDecoder3() {
|
||||||
let data = format!("{}{}{}{}{}{}{}{}{}{}",HEADER , numeric10 , numeric2alpha , alpha2isoiec646 , i646B , i646C , isoiec6462alpha ,
|
let data = format!(
|
||||||
alphaA , alpha2numeric , numeric10);
|
"{}{}{}{}{}{}{}{}{}{}",
|
||||||
let expected = "(10)BCA10";
|
HEADER,
|
||||||
|
numeric10,
|
||||||
|
numeric2alpha,
|
||||||
|
alpha2isoiec646,
|
||||||
|
i646B,
|
||||||
|
i646C,
|
||||||
|
isoiec6462alpha,
|
||||||
|
alphaA,
|
||||||
|
alpha2numeric,
|
||||||
|
numeric10
|
||||||
|
);
|
||||||
|
let expected = "(10)BCA10";
|
||||||
|
|
||||||
assertCorrectBinaryString(&data, expected);
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn testAnyAIDecodernumericFNC1secondDigit() {
|
fn testAnyAIDecodernumericFNC1secondDigit() {
|
||||||
let data = format!("{}{}{}",HEADER , numeric10 , numeric1FNC1);
|
let data = format!("{}{}{}", HEADER, numeric10, numeric1FNC1);
|
||||||
let expected = "(10)1";
|
let expected = "(10)1";
|
||||||
|
|
||||||
assertCorrectBinaryString(&data, expected);
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn testAnyAIDecoderalphaFNC1() {
|
fn testAnyAIDecoderalphaFNC1() {
|
||||||
let data = format!("{}{}{}{}{}", HEADER, numeric10 , numeric2alpha , alphaA , alphaFNC1);
|
let data = format!(
|
||||||
let expected = "(10)A";
|
"{}{}{}{}{}",
|
||||||
|
HEADER, numeric10, numeric2alpha, alphaA, alphaFNC1
|
||||||
|
);
|
||||||
|
let expected = "(10)A";
|
||||||
|
|
||||||
assertCorrectBinaryString(&data, expected);
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn testAnyAIDecoder646FNC1() {
|
fn testAnyAIDecoder646FNC1() {
|
||||||
let data = format!("{}{}{}{}{}{}{}",HEADER , numeric10 , numeric2alpha , alphaA , isoiec6462alpha , i646B , i646FNC1);
|
let data = format!(
|
||||||
let expected = "(10)AB";
|
"{}{}{}{}{}{}{}",
|
||||||
|
HEADER, numeric10, numeric2alpha, alphaA, isoiec6462alpha, i646B, i646FNC1
|
||||||
|
);
|
||||||
|
let expected = "(10)AB";
|
||||||
|
|
||||||
assertCorrectBinaryString(&data, expected);
|
assertCorrectBinaryString(&data, expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -197,8 +197,11 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
|||||||
}
|
}
|
||||||
} //while (!isFinished);
|
} //while (!isFinished);
|
||||||
|
|
||||||
if result.getDecodedInformation().is_some(){ Ok(result.getDecodedInformation().as_ref().unwrap().clone())}
|
if result.getDecodedInformation().is_some() {
|
||||||
else {Err(Exceptions::NotFoundException("".to_owned()))}
|
Ok(result.getDecodedInformation().as_ref().unwrap().clone())
|
||||||
|
} else {
|
||||||
|
Err(Exceptions::NotFoundException("".to_owned()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parseNumericBlock(&mut self) -> Result<BlockParsedRXingResult, Exceptions> {
|
fn parseNumericBlock(&mut self) -> Result<BlockParsedRXingResult, Exceptions> {
|
||||||
|
|||||||
@@ -24,19 +24,19 @@
|
|||||||
* http://www.piramidepse.com/
|
* http://www.piramidepse.com/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::oned::rss::expanded::{binary_util, decoders::{ abstract_expanded_decoder}};
|
use crate::oned::rss::expanded::{binary_util, decoders::abstract_expanded_decoder};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||||
*/
|
*/
|
||||||
#[test]
|
#[test]
|
||||||
fn testNoAi() {
|
fn testNoAi() {
|
||||||
let information = binary_util::buildBitArrayFromString(" .......X ..XX..X. X.X....X .......X ....").expect("build");
|
let information =
|
||||||
|
binary_util::buildBitArrayFromString(" .......X ..XX..X. X.X....X .......X ....")
|
||||||
|
.expect("build");
|
||||||
|
|
||||||
let mut decoder = abstract_expanded_decoder::createDecoder(&information).expect("create");
|
let mut decoder = abstract_expanded_decoder::createDecoder(&information).expect("create");
|
||||||
let decoded = decoder.parseInformation().expect("parsed");
|
let decoded = decoder.parseInformation().expect("parsed");
|
||||||
assert_eq!("(10)12A", decoded);
|
assert_eq!("(10)12A", decoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
64
src/oned/rss/expanded/expanded_row.rs
Normal file
64
src/oned/rss/expanded/expanded_row.rs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 ZXing authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
use super::ExpandedPair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One row of an RSS Expanded Stacked symbol, consisting of 1+ expanded pairs.
|
||||||
|
*/
|
||||||
|
#[derive(Hash)]
|
||||||
|
pub struct ExpandedRow {
|
||||||
|
pairs: Vec<ExpandedPair>,
|
||||||
|
rowNumber: u32,
|
||||||
|
}
|
||||||
|
impl ExpandedRow {
|
||||||
|
pub fn new(pairs: Vec<ExpandedPair>, rowNumber: u32) -> Self {
|
||||||
|
Self { pairs, rowNumber }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn getPairs(&self) -> &[ExpandedPair] {
|
||||||
|
&self.pairs
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn getRowNumber(&self) -> u32 {
|
||||||
|
self.rowNumber
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn isEquivalent(&self, otherPairs: &[ExpandedPair]) -> bool {
|
||||||
|
self.pairs == otherPairs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialEq for ExpandedRow {
|
||||||
|
/**
|
||||||
|
* Two rows are equal if they contain the same pairs in the same order.
|
||||||
|
*/
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
self.pairs == other.pairs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for ExpandedRow {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{{ ")?;
|
||||||
|
for p in &self.pairs {
|
||||||
|
write!(f, "{}", p)?;
|
||||||
|
}
|
||||||
|
write!(f, " }}") //{:?} }} " , self.pairs )
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,3 +8,6 @@ pub use expanded_pair::*;
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod expanded_information_decoder_test;
|
mod expanded_information_decoder_test;
|
||||||
|
|
||||||
|
mod expanded_row;
|
||||||
|
pub use expanded_row::*;
|
||||||
|
|||||||
Reference in New Issue
Block a user