Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parseStream(InputStream) to KlvParser #443

Closed
wants to merge 1 commit into from

Conversation

ruckc
Copy link

@ruckc ruckc commented Dec 16, 2022

Motivation and Context

#442 - reference issue. This is just a WIP attempt to provide InputStream parsing in KlvParser.

Description

Added the below method to KlvParser.

    public static void parseStream(
            InputStream is,
            Consumer<IMisbMessage> handler,
            Consumer<KlvParseException> exceptionHandler)

Given that parseBytes() throws a KlvParseException on bad data, and when dealing with a stream, you may want the ability to continue processing, this required the ability to emit IMisbMessage and/or KlvParseExceptions without breaking the stream.

How Has This Been Tested?

I tested with a mock application I'm developing where ffmpeg is running externally and its outputting the KLV data stream to stdout, which is being processed by KlvParser.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@ruckc
Copy link
Author

ruckc commented Dec 16, 2022

Just realized I based this on main/1.x branch. Updating 2.x now.

@bradh
Copy link
Collaborator

bradh commented Dec 16, 2022

Looks like a worthwhile change. The only thought I had (without a proper review) is to check that the BER and BER-OID lengths aren't excessive. If you are trying to deal with potentially corrupted data, then that can cause reading of a really large amount of data from the stream.

Also (for the general case), when things go wrong, the exception doesn't have to go uncaught, and you can log and continue.

@ruckc ruckc closed this Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants