1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
* Copyright 2007 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.common;
// import java.util.List;
use std::{any::Any, sync::Arc};
/**
* <p>Encapsulates the result of decoding a matrix of bits. This typically
* applies to 2D barcode formats. For now it contains the raw bytes obtained,
* as well as a String interpretation of those bytes, if applicable.</p>
*
* @author Sean Owen
*/
pub struct DecoderRXingResult {
rawBytes: Vec<u8>,
numBits: usize,
text: String,
byteSegments: Vec<Vec<u8>>,
ecLevel: String,
errorsCorrected: usize,
erasures: usize,
other: Option<Arc<dyn Any + Send + Sync>>,
structuredAppendParity: i32,
structuredAppendSequenceNumber: i32,
symbologyModifier: u32,
contentType: String,
isMirrored: bool,
}
impl DecoderRXingResult {
pub fn new(
rawBytes: Vec<u8>,
text: String,
byteSegments: Vec<Vec<u8>>,
ecLevel: String,
) -> Self {
Self::with_all(
rawBytes,
text,
byteSegments,
ecLevel,
-2,
-2,
0,
String::new(),
false,
)
}
pub fn with_symbology(
rawBytes: Vec<u8>,
text: String,
byteSegments: Vec<Vec<u8>>,
ecLevel: String,
symbologyModifier: u32,
) -> Self {
Self::with_all(
rawBytes,
text,
byteSegments,
ecLevel,
-1,
-1,
symbologyModifier,
String::new(),
false,
)
}
pub fn with_sa(
rawBytes: Vec<u8>,
text: String,
byteSegments: Vec<Vec<u8>>,
ecLevel: String,
saSequence: i32,
saParity: i32,
) -> Self {
Self::with_all(
rawBytes,
text,
byteSegments,
ecLevel,
saSequence,
saParity,
0,
String::new(),
false,
)
}
#[allow(clippy::too_many_arguments)]
pub fn with_all(
rawBytes: Vec<u8>,
text: String,
byteSegments: Vec<Vec<u8>>,
ecLevel: String,
saSequence: i32,
saParity: i32,
symbologyModifier: u32,
contentType: String,
isMirrored: bool,
) -> Self {
let nb = rawBytes.len();
Self {
rawBytes,
numBits: nb,
text,
byteSegments,
ecLevel,
errorsCorrected: 0,
erasures: 0,
other: None,
structuredAppendParity: saParity,
structuredAppendSequenceNumber: saSequence,
symbologyModifier,
contentType,
isMirrored,
}
}
/**
* @return raw bytes representing the result, or {@code null} if not applicable
*/
pub const fn getRawBytes(&self) -> &Vec<u8> {
&self.rawBytes
}
/**
* @return how many bits of {@link #getRawBytes()} are valid; typically 8 times its length
* @since 3.3.0
*/
pub const fn getNumBits(&self) -> usize {
self.numBits
}
/**
* @param numBits overrides the number of bits that are valid in {@link #getRawBytes()}
* @since 3.3.0
*/
pub const fn setNumBits(&mut self, numBits: usize) {
self.numBits = numBits;
}
/**
* @return text representation of the result
*/
pub fn getText(&self) -> &str {
&self.text
}
/**
* @return list of byte segments in the result, or {@code null} if not applicable
*/
pub const fn getByteSegments(&self) -> &Vec<Vec<u8>> {
&self.byteSegments
}
/**
* @return name of error correction level used, or {@code null} if not applicable
*/
pub fn getECLevel(&self) -> &str {
&self.ecLevel
}
/**
* @return number of errors corrected, or {@code null} if not applicable
*/
pub const fn getErrorsCorrected(&self) -> usize {
self.errorsCorrected
}
pub const fn setErrorsCorrected(&mut self, errorsCorrected: usize) {
self.errorsCorrected = errorsCorrected;
}
/**
* @return number of erasures corrected, or {@code null} if not applicable
*/
pub const fn getErasures(&self) -> usize {
self.erasures
}
pub const fn setErasures(&mut self, erasures: usize) {
self.erasures = erasures
}
/**
* @return arbitrary additional metadata
*/
pub fn getOther(&self) -> Option<Arc<dyn Any + Send + Sync>> {
self.other.clone()
}
pub fn setOther(&mut self, other: Option<Arc<dyn Any + Send + Sync>>) {
self.other = other
}
pub const fn hasStructuredAppend(&self) -> bool {
self.structuredAppendParity >= 0 && self.structuredAppendSequenceNumber >= 0
}
pub const fn getStructuredAppendParity(&self) -> i32 {
self.structuredAppendParity
}
pub const fn getStructuredAppendSequenceNumber(&self) -> i32 {
self.structuredAppendSequenceNumber
}
pub const fn getSymbologyModifier(&self) -> u32 {
self.symbologyModifier
}
pub fn getContentType(&self) -> &str {
&self.contentType
}
pub fn setContentType(&mut self, content_type: String) {
self.contentType = content_type
}
pub const fn getIsMirrored(&self) -> bool {
self.isMirrored
}
pub const fn setIsMirrored(&mut self, is_mirrored: bool) {
self.isMirrored = is_mirrored
}
}