Skip to content

Commit

Permalink
add basic serde support
Browse files Browse the repository at this point in the history
  • Loading branch information
hschimke committed Jan 26, 2023
1 parent 0815775 commit 6355dc1
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = []
experimental_features = []
serde = ["dep:serde"]
4 changes: 4 additions & 0 deletions src/barcode_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
4 changes: 4 additions & 0 deletions src/datamatrix/encoder/symbol_shape_hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions src/decode_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,6 +32,7 @@ use crate::{BarcodeFormat, RXingResultPointCallback};
* @author [email protected] (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 {
/**
Expand Down Expand Up @@ -137,6 +141,7 @@ pub enum DecodeHintType {
}*/
}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone)]
pub enum DecodeHintValue {
/**
Expand Down Expand Up @@ -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),

/**
Expand Down
4 changes: 4 additions & 0 deletions src/dimension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions src/encode_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected] (Daniel Switkin)
*/
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub enum EncodeHintType {
/**
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions src/pdf417/encoder/dimensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected] (Andrew Walbran)
*/
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct Dimensions {
minCols: usize,
Expand Down
4 changes: 4 additions & 0 deletions src/pdf417/pdf_417_result_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions src/rxing_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/rxing_result_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -126,6 +130,7 @@ impl From<String> for RXingResultMetadataType {
}
}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum RXingResultMetadataValue {
/**
Expand Down
4 changes: 4 additions & 0 deletions src/rxing_result_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6355dc1

Please sign in to comment.