IndiStreamDecoder constructor

IndiStreamDecoder({
  1. required void onCommand(
    1. IndiCommand command
    ),
  2. required void onError(
    1. IndiProtocolException error
    ),
  3. int maxTextLength = 4 * 1024 * 1024,
})

Creates a decoder that reports commands to onCommand and problems to onError.

Implementation

IndiStreamDecoder({
  required void Function(IndiCommand command) onCommand,
  required void Function(IndiProtocolException error) onError,
  int maxTextLength = 4 * 1024 * 1024,
}) {
  _parser = IndiXmlParser(
    maxTextLength: maxTextLength,
    onError: onError,
    onElement: (element) {
      final IndiCommand command;
      try {
        command = commandFromXml(element);
      } on IndiProtocolException catch (e) {
        onError(e);
        return;
      }
      onCommand(command);
    },
  );
}