add basic serde support

This commit is contained in:
Henry Schimke
2023-01-26 13:52:31 -06:00
parent 081577591f
commit f9ec5c5dec
11 changed files with 48 additions and 7 deletions

View File

@@ -30,6 +30,7 @@ rxing-one-d-proc-derive = "0.3"
num = "0.4.0" num = "0.4.0"
svg = {version = "0.13", optional = true} svg = {version = "0.13", optional = true}
resvg = {version = "0.28.0", optional = true, default-features=false} resvg = {version = "0.28.0", optional = true, default-features=false}
serde = { version = "1.0", features = ["derive", "rc"], optional = true }
[dev-dependencies] [dev-dependencies]
java-properties = "1.4.1" java-properties = "1.4.1"
@@ -37,10 +38,11 @@ java-rand = "0.2.0"
rand = "0.8.5" rand = "0.8.5"
[features] [features]
default = ["image"] default = ["image", "serde"]
image = ["dep:image", "dep:imageproc"] image = ["dep:image", "dep:imageproc"]
allow_forced_iso_ied_18004_compliance = [] allow_forced_iso_ied_18004_compliance = []
svg_write = ["dep:svg"] svg_write = ["dep:svg"]
svg_read = ["dep:resvg", "image"] svg_read = ["dep:resvg", "image"]
wasm_support = ["chrono/wasmbind"] wasm_support = ["chrono/wasmbind"]
experimental_features = [] experimental_features = []
serde = ["dep:serde"]

View File

@@ -18,11 +18,15 @@
use std::fmt::Display; use std::fmt::Display;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
/** /**
* Enumerates barcode formats known to this package. Please keep alphabetized. * Enumerates barcode formats known to this package. Please keep alphabetized.
* *
* @author Sean Owen * @author Sean Owen
*/ */
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub enum BarcodeFormat { pub enum BarcodeFormat {
/** Aztec 2D barcode format. */ /** Aztec 2D barcode format. */

View File

@@ -14,10 +14,14 @@
* limitations under the License. * 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 * Enumeration for DataMatrix symbol shape hint. It can be used to force square or rectangular
* symbols. * symbols.
*/ */
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum SymbolShapeHint { pub enum SymbolShapeHint {
FORCE_NONE, FORCE_NONE,

View File

@@ -20,6 +20,9 @@ use std::collections::HashSet;
use crate::{BarcodeFormat, RXingResultPointCallback}; 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 * 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, * 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) * @author dswitkin@google.com (Daniel Switkin)
* @see Reader#decode(BinaryBitmap,java.util.Map) * @see Reader#decode(BinaryBitmap,java.util.Map)
*/ */
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Eq, PartialEq, Hash, Debug, Clone, Copy)] #[derive(Eq, PartialEq, Hash, Debug, Clone, Copy)]
pub enum DecodeHintType { pub enum DecodeHintType {
/** /**
@@ -137,6 +141,7 @@ pub enum DecodeHintType {
}*/ }*/
} }
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone)] #[derive(Clone)]
pub enum DecodeHintValue { pub enum DecodeHintValue {
/** /**
@@ -196,6 +201,7 @@ pub enum DecodeHintValue {
* The caller needs to be notified via callback when a possible {@link RXingResultPoint} * The caller needs to be notified via callback when a possible {@link RXingResultPoint}
* is found. Maps to a {@link RXingResultPointCallback}. * is found. Maps to a {@link RXingResultPointCallback}.
*/ */
#[cfg_attr(feature = "serde", serde(skip_serializing, skip_deserializing))]
NeedResultPointCallback(RXingResultPointCallback), NeedResultPointCallback(RXingResultPointCallback),
/** /**

View File

@@ -20,9 +20,13 @@ use std::fmt;
use crate::Exceptions; use crate::Exceptions;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
/** /**
* Simply encapsulates a width and height. * Simply encapsulates a width and height.
*/ */
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Eq, PartialEq, Hash, Copy, Clone)] #[derive(Eq, PartialEq, Hash, Copy, Clone)]
pub struct Dimension(usize, usize); pub struct Dimension(usize, usize);

View File

@@ -18,11 +18,15 @@
use crate::{pdf417::encoder::Dimensions, Dimension}; 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. * These are a set of hints that you may pass to Writers to specify their behavior.
* *
* @author dswitkin@google.com (Daniel Switkin) * @author dswitkin@google.com (Daniel Switkin)
*/ */
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub enum EncodeHintType { pub enum EncodeHintType {
/** /**
@@ -176,6 +180,7 @@ pub enum EncodeHintType {
CODE128_COMPACT, CODE128_COMPACT,
} }
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum EncodeHintValue { pub enum EncodeHintValue {
/** /**
* Specifies what degree of error correction to use, for example in QR Codes. * Specifies what degree of error correction to use, for example in QR Codes.

View File

@@ -14,11 +14,15 @@
* limitations under the License. * 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. * Data object to specify the minimum and maximum number of rows and columns for a PDF417 barcode.
* *
* @author qwandor@google.com (Andrew Walbran) * @author qwandor@google.com (Andrew Walbran)
*/ */
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Eq, PartialEq)] #[derive(Copy, Clone, Eq, PartialEq)]
pub struct Dimensions { pub struct Dimensions {
minCols: usize, minCols: usize,

View File

@@ -14,9 +14,13 @@
* limitations under the License. * limitations under the License.
*/ */
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
/** /**
* @author Guenther Grau * @author Guenther Grau
*/ */
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub struct PDF417RXingResultMetadata { pub struct PDF417RXingResultMetadata {
segmentIndex: usize, segmentIndex: usize,

View File

@@ -14,20 +14,19 @@
* limitations under the License. * limitations under the License.
*/ */
//package com.google.zxing;
//import java.util.EnumMap;
//import java.util.Map;
use std::{collections::HashMap, fmt}; use std::{collections::HashMap, fmt};
use crate::{BarcodeFormat, RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint}; use crate::{BarcodeFormat, RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
/** /**
* <p>Encapsulates the result of decoding a barcode within an image.</p> * <p>Encapsulates the result of decoding a barcode within an image.</p>
* *
* @author Sean Owen * @author Sean Owen
*/ */
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone)] #[derive(Clone)]
pub struct RXingResult { pub struct RXingResult {
text: String, text: String,

View File

@@ -20,12 +20,16 @@ use std::rc::Rc;
use crate::pdf417::PDF417RXingResultMetadata; 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 * Represents some type of metadata about the result of the decoding that the decoder
* wishes to communicate back to the caller. * wishes to communicate back to the caller.
* *
* @author Sean Owen * @author Sean Owen
*/ */
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Eq, PartialEq, Hash, Debug, Clone)] #[derive(Eq, PartialEq, Hash, Debug, Clone)]
pub enum RXingResultMetadataType { pub enum RXingResultMetadataType {
/** /**
@@ -126,6 +130,7 @@ impl From<String> for RXingResultMetadataType {
} }
} }
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]
pub enum RXingResultMetadataValue { pub enum RXingResultMetadataValue {
/** /**

View File

@@ -3,12 +3,16 @@ use std::{fmt, iter::Sum};
use crate::ResultPoint; use crate::ResultPoint;
use std::hash::Hash; use std::hash::Hash;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
/** /**
* <p>Encapsulates a point of interest in an image containing a barcode. Typically, this * <p>Encapsulates 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.</p> * would be the location of a finder pattern or the corner of the barcode, for example.</p>
* *
* @author Sean Owen * @author Sean Owen
*/ */
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Default)] #[derive(Debug, Clone, Copy, Default)]
pub struct RXingResultPoint { pub struct RXingResultPoint {
pub(crate) x: f32, pub(crate) x: f32,