diff --git a/Cargo.toml b/Cargo.toml index 80faf1f..0e1aeef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ rxing-one-d-proc-derive = "0.3" num = "0.4.0" svg = {version = "0.13", optional = true} resvg = {version = "0.28.0", optional = true, default-features=false} +serde = { version = "1.0", features = ["derive", "rc"], optional = true } [dev-dependencies] java-properties = "1.4.1" @@ -43,4 +44,5 @@ allow_forced_iso_ied_18004_compliance = [] svg_write = ["dep:svg"] svg_read = ["dep:resvg", "image"] wasm_support = ["chrono/wasmbind"] -experimental_features = [] \ No newline at end of file +experimental_features = [] +serde = ["dep:serde"] \ No newline at end of file diff --git a/src/barcode_format.rs b/src/barcode_format.rs index 50b05e0..0f1f45f 100644 --- a/src/barcode_format.rs +++ b/src/barcode_format.rs @@ -18,11 +18,15 @@ use std::fmt::Display; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + /** * Enumerates barcode formats known to this package. Please keep alphabetized. * * @author Sean Owen */ +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] pub enum BarcodeFormat { /** Aztec 2D barcode format. */ diff --git a/src/datamatrix/encoder/symbol_shape_hint.rs b/src/datamatrix/encoder/symbol_shape_hint.rs index d0eabf5..aad6ea1 100644 --- a/src/datamatrix/encoder/symbol_shape_hint.rs +++ b/src/datamatrix/encoder/symbol_shape_hint.rs @@ -14,10 +14,14 @@ * limitations under the License. */ +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + /** * Enumeration for DataMatrix symbol shape hint. It can be used to force square or rectangular * symbols. */ +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum SymbolShapeHint { FORCE_NONE, diff --git a/src/decode_hints.rs b/src/decode_hints.rs index 905fdb7..53649a4 100644 --- a/src/decode_hints.rs +++ b/src/decode_hints.rs @@ -20,6 +20,9 @@ use std::collections::HashSet; use crate::{BarcodeFormat, RXingResultPointCallback}; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + /** * Encapsulates a type of hint that a caller may pass to a barcode reader to help it * more quickly or accurately decode it. It is up to implementations to decide what, @@ -29,6 +32,7 @@ use crate::{BarcodeFormat, RXingResultPointCallback}; * @author dswitkin@google.com (Daniel Switkin) * @see Reader#decode(BinaryBitmap,java.util.Map) */ +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Eq, PartialEq, Hash, Debug, Clone, Copy)] pub enum DecodeHintType { /** @@ -137,6 +141,7 @@ pub enum DecodeHintType { }*/ } +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Clone)] pub enum DecodeHintValue { /** @@ -196,6 +201,7 @@ pub enum DecodeHintValue { * The caller needs to be notified via callback when a possible {@link RXingResultPoint} * is found. Maps to a {@link RXingResultPointCallback}. */ + #[cfg_attr(feature = "serde", serde(skip_serializing, skip_deserializing))] NeedResultPointCallback(RXingResultPointCallback), /** diff --git a/src/dimension.rs b/src/dimension.rs index 2a21c50..ea439c7 100644 --- a/src/dimension.rs +++ b/src/dimension.rs @@ -20,9 +20,13 @@ use std::fmt; use crate::Exceptions; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + /** * Simply encapsulates a width and height. */ +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Eq, PartialEq, Hash, Copy, Clone)] pub struct Dimension(usize, usize); diff --git a/src/encode_hints.rs b/src/encode_hints.rs index 5bc529a..ed26d65 100644 --- a/src/encode_hints.rs +++ b/src/encode_hints.rs @@ -16,13 +16,19 @@ //package com.google.zxing; +#![allow(deprecated)] + use crate::{pdf417::encoder::Dimensions, Dimension}; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + /** * These are a set of hints that you may pass to Writers to specify their behavior. * * @author dswitkin@google.com (Daniel Switkin) */ +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] pub enum EncodeHintType { /** @@ -176,6 +182,7 @@ pub enum EncodeHintType { CODE128_COMPACT, } +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum EncodeHintValue { /** * Specifies what degree of error correction to use, for example in QR Codes. diff --git a/src/pdf417/encoder/dimensions.rs b/src/pdf417/encoder/dimensions.rs index c0c68dd..354be7a 100644 --- a/src/pdf417/encoder/dimensions.rs +++ b/src/pdf417/encoder/dimensions.rs @@ -14,11 +14,15 @@ * limitations under the License. */ +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + /** * Data object to specify the minimum and maximum number of rows and columns for a PDF417 barcode. * * @author qwandor@google.com (Andrew Walbran) */ +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Copy, Clone, Eq, PartialEq)] pub struct Dimensions { minCols: usize, diff --git a/src/pdf417/pdf_417_result_metadata.rs b/src/pdf417/pdf_417_result_metadata.rs index 7256eee..6796352 100644 --- a/src/pdf417/pdf_417_result_metadata.rs +++ b/src/pdf417/pdf_417_result_metadata.rs @@ -14,9 +14,13 @@ * limitations under the License. */ +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + /** * @author Guenther Grau */ +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug, PartialEq, Eq)] pub struct PDF417RXingResultMetadata { segmentIndex: usize, diff --git a/src/rxing_result.rs b/src/rxing_result.rs index 6225e78..2176aac 100644 --- a/src/rxing_result.rs +++ b/src/rxing_result.rs @@ -14,20 +14,19 @@ * limitations under the License. */ -//package com.google.zxing; - -//import java.util.EnumMap; -//import java.util.Map; - use std::{collections::HashMap, fmt}; use crate::{BarcodeFormat, RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint}; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + /** *
Encapsulates the result of decoding a barcode within an image.
* * @author Sean Owen */ +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Clone)] pub struct RXingResult { text: String, diff --git a/src/rxing_result_metadata.rs b/src/rxing_result_metadata.rs index ba0aa25..01dca20 100644 --- a/src/rxing_result_metadata.rs +++ b/src/rxing_result_metadata.rs @@ -20,12 +20,16 @@ use std::rc::Rc; use crate::pdf417::PDF417RXingResultMetadata; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + /** * Represents some type of metadata about the result of the decoding that the decoder * wishes to communicate back to the caller. * * @author Sean Owen */ +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Eq, PartialEq, Hash, Debug, Clone)] pub enum RXingResultMetadataType { /** @@ -126,6 +130,7 @@ impl FromEncapsulates a point of interest in an image containing a barcode. Typically, this * would be the location of a finder pattern or the corner of the barcode, for example.
* * @author Sean Owen */ +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug, Clone, Copy, Default)] pub struct RXingResultPoint { pub(crate) x: f32,