react-native-scanbot-sdk
Version:
Scanbot Document and Barcode Scanner SDK React Native Plugin for Android and iOS
111 lines (97 loc) • 2.85 kB
text/typescript
/// Auto-generated with ScanbotSDKCodegenV3. Modifications will be overwritten.
/// Generated from rtu-ui-v2/schemas/barcode/BarcodeScannerUIResult.yaml
import { BarcodeItem } from '../../barcode/BarcodeScannerTypes';
import { ToJsonConfiguration } from '../../utils/json/JsonSerializationTypes';
import { DeepPartial, PartiallyConstructible } from '../../utils/utils';
/**
Data about the scanned barcode.
*/
export class BarcodeScannerUiItem extends PartiallyConstructible {
/**
Scanned barcode.
*/
public readonly barcode: BarcodeItem;
/**
Number of scanned barcodes of this symbology and value.
*/
public readonly count: number;
/** @param source {@displayType `DeepPartial<BarcodeScannerUiItem>`} */
public constructor(source: DeepPartial<BarcodeScannerUiItem> = {}) {
super();
if (source.barcode !== undefined) {
this.barcode = new BarcodeItem(source.barcode);
} else {
throw new Error('barcode must be present in constructor argument');
}
if (source.count !== undefined) {
this.count = source.count;
} else {
throw new Error('count must be present in constructor argument');
}
}
public async serialize(
config: ToJsonConfiguration = new ToJsonConfiguration()
): Promise<DeepPartial<BarcodeScannerUiItem>> {
return {
barcode: await this.barcode.serialize(config),
count: this.count,
};
}
private _released: Boolean = false;
public release() {
if (this._released) {
return;
}
this.barcode.release();
this._released = true;
}
public async encodeImages(): Promise<void> {
await this.barcode.encodeImages();
}
}
/**
Results of the barcode scan.
*/
export class BarcodeScannerUiResult extends PartiallyConstructible {
/**
Scanned barcode items.
*/
public readonly items: BarcodeScannerUiItem[] = [];
/** @param source {@displayType `DeepPartial<BarcodeScannerUiResult>`} */
public constructor(source: DeepPartial<BarcodeScannerUiResult> = {}) {
super();
if (source.items !== undefined) {
this.items = source.items.map((it: any) => {
return new BarcodeScannerUiItem(it);
});
}
}
public async serialize(
config: ToJsonConfiguration = new ToJsonConfiguration()
): Promise<DeepPartial<BarcodeScannerUiResult>> {
return {
items: await Promise.all(
this.items.map(async (it: any) => {
return await it.serialize(config);
})
),
};
}
private _released: Boolean = false;
public release() {
if (this._released) {
return;
}
this.items.forEach((it) => {
it.release();
});
this._released = true;
}
public async encodeImages(): Promise<void> {
await Promise.all(
this.items.map(async (it) => {
await it.encodeImages();
})
);
}
}