2020-09-08 14:59:06 +00:00
|
|
|
/**
|
|
|
|
* @author Martin Karkowski
|
|
|
|
* @email m.karkowski@zema.de
|
|
|
|
* @create date 2018-05-22 12:38:40
|
2020-09-10 16:21:19 +00:00
|
|
|
* @modify date 2020-09-09 16:02:48
|
2020-09-08 14:59:06 +00:00
|
|
|
* @desc [description]
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { inject, injectable } from 'inversify';
|
|
|
|
import * as GRPC from '../../mod-GRPC-Interface/assembly/manual-assembly';
|
|
|
|
import { SystemLogger } from '../../mod-Logger/src/Unique.Logger';
|
|
|
|
import { AvailableFromConvertes, AvailableToConvertes, IConverter, IGrpcConfiguration } from '../type/interfaces';
|
|
|
|
|
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class FromGrpcConverter implements IConverter<Buffer, any, IGrpcConfiguration> {
|
|
|
|
public readonly name: AvailableFromConvertes | AvailableToConvertes;
|
|
|
|
|
|
|
|
private _logger = SystemLogger.logger.getLogger('converter.from.grpc');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Container for the Registered Topics
|
|
|
|
* @private
|
|
|
|
* @memberof BaseHTMLConverter
|
|
|
|
*/
|
|
|
|
private _convertOptions = new Map<string, any>();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register only Endpoints.
|
|
|
|
*
|
|
|
|
* @param {string} identifier The Identifier for the Convertert
|
|
|
|
* @param {IDa3vidConfiguration} config The Config to use.
|
|
|
|
* @memberof BaseDa3vidConverter
|
|
|
|
*/
|
|
|
|
register(identifier: string, config: IGrpcConfiguration): void {
|
|
|
|
this._convertOptions.set(identifier, config);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts the Data.
|
|
|
|
*
|
|
|
|
* @param {*} data The Data to use.
|
|
|
|
* @param {string} identifier the Identifier to convert the Data
|
|
|
|
* @param {number} timeStamp the given TimeStamp.
|
|
|
|
* @returns {IDa3vidData}
|
|
|
|
* @memberof BaseDa3vidConverter
|
|
|
|
*/
|
|
|
|
convert(data: Buffer, identifier: string | null = null, timeStamp: number | null = null): any {
|
|
|
|
if (identifier != null) {
|
|
|
|
const config: IGrpcConfiguration = this._convertOptions.get(identifier);
|
|
|
|
if (config) {
|
|
|
|
return this._grpcRegistry.genMessage(config.packageName, config.messageName, data, 'decode');
|
|
|
|
}
|
|
|
|
|
|
|
|
const err = new TypeError('Type not registered for the From-GRPC-Conveter on ' + identifier);
|
2020-09-10 16:21:19 +00:00
|
|
|
this._logger.error('Type not registered for the From-GRPC-Conveter on "' + identifier + '"', err);
|
2020-09-08 14:59:06 +00:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
const err = new TypeError('Identifier must be provided for the From-GRPC-Converter');
|
|
|
|
this._logger.error('Identifier must be provided for the From-GRPC-Converter', err);
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an instance of FromGrpcConverter.
|
|
|
|
* @param {GRPC.Registery} _grpcRegistry
|
|
|
|
* @param {LOGGING.Logger} _logger
|
|
|
|
* @memberof FromGrpcConverter
|
|
|
|
*/
|
|
|
|
constructor(
|
|
|
|
@inject(GRPC.TYPES.Registry) private _grpcRegistry: GRPC.Registery,
|
|
|
|
) {
|
|
|
|
this.name = 'from-grpc';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|