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

ByteDataReader Offset - setter #11

Open
gouthamrg opened this issue Jan 25, 2024 · 3 comments
Open

ByteDataReader Offset - setter #11

gouthamrg opened this issue Jan 25, 2024 · 3 comments

Comments

@gouthamrg
Copy link

I am working on a project where I would need to update the offset position. Something similar to MemoryStream class in C#, Where Stream position can be updated.

I see there is a getter for OffsetInBytes. I think enabling this feature adds more value to this solution.

@isoos
Copy link
Owner

isoos commented Jan 25, 2024

Not sure what you are trying to do here: could you please give a more detailed example of the use case and what's missing?

@gouthamrg gouthamrg changed the title Offset - setter ByteDataReader Offset - setter Jan 25, 2024
@gouthamrg
Copy link
Author

gouthamrg commented Jan 25, 2024

Thanks @isoos for the quick reply.
Sorry, I missed adding more context. I am using the ByteDataReader to read the bytes, in the stream, every message starts with a particular header and ends with a footer. While reading them, I parse byte by byte till I reach the header byte. The read method in ByteDataReader updates the offset position, Once I find the header byte, I want to reset the offset to offset - 1.

@isoos
Copy link
Owner

isoos commented Jan 25, 2024

ByteDataReader was designed to parse the input only once, as otherwise it should buffer all or parts of it, which increases the number of extra checks it needs to do for every single read. I'd be cautious of adding such feature in it, maybe as a wrapper class on top of it.

However, your use case suggest that you may be working with headers, and that is not an uncommon parsing problem. Previously I've done this with a combination of a buffer that I write the unfinished header bytes until the boundary condition comes, and then parse+process the header, continuing on the input stream after that.

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

No branches or pull requests

2 participants