nope/modules/mod-Converters
2020-09-10 18:21:19 +02:00
..
assembly Updating Modules 2020-09-10 18:21:19 +02:00
src Updating Modules 2020-09-10 18:21:19 +02:00
test Updating modules 2020-09-08 16:59:06 +02:00
type Updating modules 2020-09-08 16:59:06 +02:00
README.md Updating modules 2020-09-08 16:59:06 +02:00

Converter Module

The Module is used to allow the convertion between different data formats. Each converter is defined in a separate file (see /src - Folder) and is automatically integrated int the Converter-Container.

Therefore each converter implements the following Interface (see /type/interface.ts)

export interface IConverter<Input, Return, Config> {
    /** Name of the Converter */ 
    name: AvailableFromConvertes | AvailableToConvertes;
    /** Function to convert the Input to the Output */
    convert (data: Input, path?: string, timeStamp?: number): Return;
    /** To allow a configuration the converter the register-method is provided */
    register(topic: string, config: Config): void;
}

Example of Usage

An example of the usage is given in /test/test-converters.ts

Rules:

  • Try using the Container
  • use identifiers to register different converters
/** Import the Assembly*/
import * as CONVERTERS from '../path/to/git/assembly/manual-assembly';

/** Import an INVERSIFY Container */
import { Container } from 'inversify';

/** Create a Container and include the defined Module */
const _container = new Container();
_container.load(CONVERTERS.CONTAINERMODULE);

/** Create an Instance */
const _converter = _container.get<CONVERTERS.ConverterContainer>(CONVERTERS.TYPES.Converter);

/** Register an Identifier */
_converter.register('to-grpc', 'identifier', {
    /** Setting the X-Position */
    fileName: 'Proto-Repository\\protos\\std_messages.proto',
    packageName: 'std_package',
    messageName: 'Orientation_rpy'
});

/** Convert Stuff */
const _buf = _converter.autoConvert({roll: 1, pitch: 0 , yaw: 0}, 'identifier');

Extending the Converter

  1. To extend the Converter adapt the following vars of the /type/interfaces.ts

    • AvailableToConvertes
      export type AvailableToConvertes = 'to-grpc' | 'to-csv' | 'to-da3vid' | 'to-json' | 'to-html' | 'to-string' /** | 'add-your-name-here' */;
      
    • AvailableFromConvertes
      export type AvailableFromConvertes = 'from-grpc' | 'from-json' /** | 'or-here' */;
      
    • AvailableConfigType
      export type AvailableConfigType = IGrpcConfiguration | IDa3vidConfiguration | IHtmlConfiguration /** | IYourConfigInterfaceHere */ ;
      
  2. Create the corresponding Class-File in /src

    1. Implement the IConverter<Input, Return, Config>-Interface
    2. Make the calss injectable
    @injectable()
    export class YourConverter implements IConverter<any, string, number> {
       ...
    }
    
  3. Adapt the manual Assembly and add your converter ( see /assembly/manual-assembly.ts)

    1. Import your defined Interfaces and Classes
    2. Add a Binding for your class (use inSingletonScope)
      /** Binding for To String Converter */
      bind<IConverter<any, string, any>>(TYPES.ToStringConverter).to(ToStringConverter).inSingletonScope();
      
    3. Export your defined Converters as Type.

These steps are required to automatically include the converter into the Container.