add basic serde support

This commit is contained in:
Henry Schimke
2023-01-26 14:01:29 -06:00
parent 081577591f
commit 6355dc1bfd
11 changed files with 49 additions and 6 deletions

View File

@@ -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"
@@ -44,3 +45,4 @@ svg_write = ["dep:svg"]
svg_read = ["dep:resvg", "image"]
wasm_support = ["chrono/wasmbind"]
experimental_features = []
serde = ["dep:serde"]

View File

@@ -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. */

View File

@@ -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,

View File

@@ -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),
/**

View File

@@ -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);

View File

@@ -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.

View File

@@ -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,

View File

@@ -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,

View File

@@ -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};
/**
* <p>Encapsulates the result of decoding a barcode within an image.</p>
*
* @author Sean Owen
*/
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone)]
pub struct RXingResult {
text: String,

View File

@@ -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 From<String> for RXingResultMetadataType {
}
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum RXingResultMetadataValue {
/**

View File

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