build result

This commit is contained in:
Henry Schimke
2023-04-23 11:23:56 -05:00
parent b4f99b3195
commit cb7050a5dd
4 changed files with 58 additions and 63 deletions

View File

@@ -16,7 +16,10 @@
use std::{collections::HashMap, fmt};
use crate::{BarcodeFormat, Point, RXingResultMetadataType, RXingResultMetadataValue};
use crate::{
common::cpp_essentials::DecoderResult, BarcodeFormat, MetadataDictionary, Point,
RXingResultMetadataType, RXingResultMetadataValue,
};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
@@ -95,6 +98,44 @@ impl RXingResult {
}
}
pub fn with_decoder_result<T>(
res: DecoderResult<T>,
resultPoints: &[Point],
format: BarcodeFormat,
) -> Self
where
T: Copy + Clone + Default + Eq + PartialEq,
{
let mut new_res = Self::new(
&res.text(),
res.content().bytes().to_vec(),
resultPoints.to_vec(),
format,
);
let mut meta_data = MetadataDictionary::new();
meta_data.insert(
RXingResultMetadataType::ERROR_CORRECTION_LEVEL,
RXingResultMetadataValue::ErrorCorrectionLevel(res.ecLevel().to_owned()),
);
meta_data.insert(
RXingResultMetadataType::STRUCTURED_APPEND_PARITY,
RXingResultMetadataValue::StructuredAppendParity(res.structuredAppend().count),
);
meta_data.insert(
RXingResultMetadataType::STRUCTURED_APPEND_SEQUENCE,
RXingResultMetadataValue::StructuredAppendSequence(res.structuredAppend().index),
);
meta_data.insert(
RXingResultMetadataType::SYMBOLOGY_IDENTIFIER,
RXingResultMetadataValue::SymbologyIdentifier(res.symbologyIdentifier()),
);
new_res.putAllMetadata(meta_data);
new_res
}
/**
* @return raw text encoded by the barcode
*/