Skip to main content

rxing/
rxing_result_metadata.rs

1/*
2 * Copyright 2008 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//package com.google.zxing;
18
19use std::sync::Arc;
20
21use crate::pdf417::PDF417RXingResultMetadata;
22
23#[cfg(feature = "serde")]
24use serde::{Deserialize, Serialize};
25
26/**
27 * Represents some type of metadata about the result of the decoding that the decoder
28 * wishes to communicate back to the caller.
29 *
30 * @author Sean Owen
31 */
32#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
33#[derive(Eq, PartialEq, Hash, Debug, Clone)]
34pub enum RXingResultMetadataType {
35    /**
36     * Unspecified, application-specific metadata. Maps to an unspecified {@link Object}.
37     */
38    OTHER,
39
40    /**
41     * Denotes the likely approximate orientation of the barcode in the image. This value
42     * is given as degrees rotated clockwise from the normal, upright orientation.
43     * For example a 1D barcode which was found by reading top-to-bottom would be
44     * said to have orientation "90". This key maps to an {@link Integer} whose
45     * value is in the range [0,360).
46     */
47    ORIENTATION,
48
49    /**
50     * <p>2D barcode formats typically encode text, but allow for a sort of 'byte mode'
51     * which is sometimes used to encode binary data. While {@link RXingResult} makes available
52     * the complete raw bytes in the barcode for these formats, it does not offer the bytes
53     * from the byte segments alone.</p>
54     *
55     * <p>This maps to a {@link java.util.List} of byte arrays corresponding to the
56     * raw bytes in the byte segments in the barcode, in order.</p>
57     */
58    BYTE_SEGMENTS,
59
60    /**
61     * Error correction level used, if applicable. The value type depends on the
62     * format, but is typically a String.
63     */
64    ERROR_CORRECTION_LEVEL,
65
66    /**
67     * For some periodicals, indicates the issue number as an {@link Integer}.
68     */
69    ISSUE_NUMBER,
70
71    /**
72     * For some products, indicates the suggested retail price in the barcode as a
73     * formatted {@link String}.
74     */
75    SUGGESTED_PRICE,
76
77    /**
78     * For some products, the possible country of manufacture as a {@link String} denoting the
79     * ISO country code. Some map to multiple possible countries, like "US/CA".
80     */
81    POSSIBLE_COUNTRY,
82
83    /**
84     * For some products, the extension text
85     */
86    UPC_EAN_EXTENSION,
87
88    /**
89     * PDF417-specific metadata
90     */
91    PDF417_EXTRA_METADATA,
92
93    /**
94     * If the code format supports structured append and the current scanned code is part of one then the
95     * sequence number is given with it.
96     */
97    STRUCTURED_APPEND_SEQUENCE,
98
99    /**
100     * If the code format supports structured append and the current scanned code is part of one then the
101     * parity is given with it.
102     */
103    STRUCTURED_APPEND_PARITY,
104
105    /**
106     * Barcode Symbology Identifier.
107     * Note: According to the GS1 specification the identifier may have to replace a leading FNC1/GS character
108     * when prepending to the barcode content.
109     */
110    SYMBOLOGY_IDENTIFIER,
111
112    IS_MIRRORED,
113
114    CONTENT_TYPE,
115
116    IS_INVERTED,
117
118    // In a filtered context, was the image "closed"
119    FILTERED_CLOSED,
120
121    // In a filtered context, what was the final read resolution
122    FILTERED_RESOLUTION,
123}
124
125impl From<String> for RXingResultMetadataType {
126    fn from(in_str: String) -> Self {
127        match in_str.to_uppercase().as_str() {
128            "OTHER" => RXingResultMetadataType::OTHER,
129            "ORIENTATION" => RXingResultMetadataType::ORIENTATION,
130            "BYTE_SEGMENTS" | "BYTESEGMENTS" => RXingResultMetadataType::BYTE_SEGMENTS,
131            "ERROR_CORRECTION_LEVEL" | "ERRORCORRECTIONLEVEL" | "ECLEVEL" => {
132                RXingResultMetadataType::ERROR_CORRECTION_LEVEL
133            }
134            "ISSUE_NUMBER" | "ISSUENUMBER" => RXingResultMetadataType::ISSUE_NUMBER,
135            "SUGGESTED_PRICE" | "SUGGESTEDPRICE" => RXingResultMetadataType::SUGGESTED_PRICE,
136            "POSSIBLE_COUNTRY" | "POSSIBLECOUNTRY" => RXingResultMetadataType::POSSIBLE_COUNTRY,
137            "UPC_EAN_EXTENSION" | "UPCEANEXTENSION" => RXingResultMetadataType::UPC_EAN_EXTENSION,
138            "PDF417_EXTRA_METADATA" | "PDF417EXTRAMETADATA" => {
139                RXingResultMetadataType::PDF417_EXTRA_METADATA
140            }
141            "STRUCTURED_APPEND_SEQUENCE" | "STRUCTUREDAPPENDSEQUENCE" => {
142                RXingResultMetadataType::STRUCTURED_APPEND_SEQUENCE
143            }
144            "STRUCTURED_APPEND_PARITY" | "STRUCTUREDAPPENDPARITY" => {
145                RXingResultMetadataType::STRUCTURED_APPEND_PARITY
146            }
147            "SYMBOLOGY_IDENTIFIER" | "SYMBOLOGYIDENTIFIER" => {
148                RXingResultMetadataType::SYMBOLOGY_IDENTIFIER
149            }
150            "IS_MIRRORED" | "ISMIRRORED" => RXingResultMetadataType::IS_MIRRORED,
151            "CONTENT_TYPE" | "CONTENTTYPE" => RXingResultMetadataType::CONTENT_TYPE,
152            "ISINVERTED" => RXingResultMetadataType::IS_INVERTED,
153            "FILTERED_CLOSED" => RXingResultMetadataType::FILTERED_CLOSED,
154            "FILTERED_RESOLUTION" => RXingResultMetadataType::FILTERED_RESOLUTION,
155            _ => RXingResultMetadataType::OTHER,
156        }
157    }
158}
159
160#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
161#[derive(Debug, PartialEq, Eq, Clone)]
162pub enum RXingResultMetadataValue {
163    /**
164     * Unspecified, application-specific metadata. Maps to an unspecified {@link Object}.
165     */
166    OTHER(String),
167
168    /**
169     * Denotes the likely approximate orientation of the barcode in the image. This value
170     * is given as degrees rotated clockwise from the normal, upright orientation.
171     * For example a 1D barcode which was found by reading top-to-bottom would be
172     * said to have orientation "90". This key maps to an {@link Integer} whose
173     * value is in the range [0,360).
174     */
175    Orientation(i32),
176
177    /**
178     * <p>2D barcode formats typically encode text, but allow for a sort of 'byte mode'
179     * which is sometimes used to encode binary data. While {@link RXingResult} makes available
180     * the complete raw bytes in the barcode for these formats, it does not offer the bytes
181     * from the byte segments alone.</p>
182     *
183     * <p>This maps to a {@link java.util.List} of byte arrays corresponding to the
184     * raw bytes in the byte segments in the barcode, in order.</p>
185     */
186    ByteSegments(Vec<Vec<u8>>),
187
188    /**
189     * Error correction level used, if applicable. The value type depends on the
190     * format, but is typically a String.
191     */
192    ErrorCorrectionLevel(String),
193
194    /**
195     * For some periodicals, indicates the issue number as an {@link Integer}.
196     */
197    IssueNumber(i32),
198
199    /**
200     * For some products, indicates the suggested retail price in the barcode as a
201     * formatted {@link String}.
202     */
203    SuggestedPrice(String),
204
205    /**
206     * For some products, the possible country of manufacture as a {@link String} denoting the
207     * ISO country code. Some map to multiple possible countries, like "US/CA".
208     */
209    PossibleCountry(String),
210
211    /**
212     * For some products, the extension text
213     */
214    UpcEanExtension(String),
215
216    /**
217     * PDF417-specific metadata
218     */
219    Pdf417ExtraMetadata(Arc<PDF417RXingResultMetadata>),
220
221    /**
222     * If the code format supports structured append and the current scanned code is part of one then the
223     * sequence number is given with it.
224     */
225    StructuredAppendSequence(i32),
226
227    /**
228     * If the code format supports structured append and the current scanned code is part of one then the
229     * parity is given with it.
230     */
231    StructuredAppendParity(i32),
232
233    /**
234     * Barcode Symbology Identifier.
235     * Note: According to the GS1 specification the identifier may have to replace a leading FNC1/GS character
236     * when prepending to the barcode content.
237     */
238    SymbologyIdentifier(String),
239
240    IsMirrored(bool),
241
242    ContentType(String),
243
244    IsInverted(bool),
245
246    FilteredClosed(bool),
247
248    FilteredResolution((usize, usize)),
249}