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 optional argument to ReadNext that allows precise seeking #11

Merged
merged 4 commits into from
Jun 18, 2021

Conversation

cvium
Copy link
Contributor

@cvium cvium commented Jun 17, 2021

bonus: allow LeaveContainer to be called without reading to the end

Reason for changes

I am trying to write a fast parser for the Matroska container, which Ebml was originally made for. Your lib seems to be the best way to achieve this without big rewrites.

I have added an optional argument to ReadNext which allows reading the next element at a specific position. In conjunction with SeekHead this enables you to seek to a desired segment without seeking through the whole file.

As a bonus I made some changes to LeaveContainer such that it handles leaving a container without reading all elements. I didn't see a reason not to allow it, but maybe you have/had a valid reason?

@cvium
Copy link
Contributor Author

cvium commented Jun 17, 2021

Bonus question: How do you feel about updating to .NET 5? This would require removing support for .Net Framework.

@OlegZee
Copy link
Owner

OlegZee commented Jun 17, 2021

@cvium thanks for bringing that. I don't like an idea of making optional parameter for various reasons such as poor binary compatibility, poor class contract. The purpose of the method is not exactly followed and redundant actions are made.

My suggestion is to make another method and call it ReadAt(long position). Let's discuss that approach.

re upgrading: what's the purpose?
My knowledge might be a little outdated but as far as I remember netstandard target provides best compatibility across all existing netcore runtimes.

@cvium
Copy link
Contributor Author

cvium commented Jun 17, 2021

@cvium thanks for bringing that. I don't like an idea of making optional parameter for various reasons such as poor binary compatibility, poor class contract. The purpose of the method is not exactly followed and redundant actions are made.

My suggestion is to make another method and call it ReadAt(long position). Let's discuss that approach.

I did that initially but ended up basically copying ReadNext. I've made it a bit cleaner now I think.

re upgrading: what's the purpose?
My knowledge might be a little outdated but as far as I remember netstandard target provides best compatibility across all existing netcore runtimes.

You are correct, but Netstandard is outdated and from .NET 5 there is no longer netstandard and netcore. There's only netX.0 moving forward.

The benefit for NEbml is the addition of Span and Memory structs, which are significantly faster and has a smaller memory footprint (stack allocations instead of heap).

@OlegZee
Copy link
Owner

OlegZee commented Jun 18, 2021

That looks good! However why did you change ReadNext implementation?
While reverting the original implementation please move new ReatAt method under ReadNext so that the diff won't interleave for both methods.
re net5: I will add new target then (#12).

@cvium
Copy link
Contributor Author

cvium commented Jun 18, 2021

I have moved ReadAt below ReadNext.

However why did you change ReadNext implementation?

I didn't change it per se. I extracted the Element-parsing to its own private method because ReadNext and ReadAt both require it.

@OlegZee
Copy link
Owner

OlegZee commented Jun 18, 2021

Nice, thank you!

@OlegZee OlegZee closed this Jun 18, 2021
@OlegZee OlegZee reopened this Jun 18, 2021
@OlegZee OlegZee merged commit 2a96e3a into OlegZee:master Jun 18, 2021
@cvium cvium deleted the readnext-with-position branch June 18, 2021 06:55
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