.. | ||
assembly | ||
src | ||
test | ||
type | ||
README.md |
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
-
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 */ ;
- AvailableToConvertes
-
Create the corresponding Class-File in
/src
- Implement the
IConverter<Input, Return, Config>
-Interface - Make the calss injectable
@injectable() export class YourConverter implements IConverter<any, string, number> { ... }
- Implement the
-
Adapt the manual Assembly and add your converter ( see
/assembly/manual-assembly.ts
)- Import your defined Interfaces and Classes
- Add a Binding for your class (use inSingletonScope)
/** Binding for To String Converter */ bind<IConverter<any, string, any>>(TYPES.ToStringConverter).to(ToStringConverter).inSingletonScope();
- Export your defined Converters as Type.
These steps are required to automatically include the converter into the Container.