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

Implemented method Slice in DataStream #150

Closed
wants to merge 7 commits into from

Conversation

Megaflan
Copy link
Contributor

@Megaflan Megaflan commented Oct 17, 2020

Description

Added a Slice method based on the Span<T> seen in C# 8.0 using the new method WriteSegmentTo() as a base.
Using the method Slice will create a new DataStream based on a starting offset parameter or a starting offset parameter + length.

Example

stream.Slice(long start)
stream.Slice(long start, long length)

Closes #143

Copy link
Member

@pleonex pleonex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start to look good but we should do the substream instead of copies.

src/Yarhl/IO/DataStream.cs Outdated Show resolved Hide resolved
src/Yarhl.UnitTests/IO/DataStreamTests.cs Outdated Show resolved Hide resolved
Copy link
Member

@pleonex pleonex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks perfect. Just one more adjustment to the test to ensure the behavior is what we expect in the design.


DataStream testSlice = stream.Slice(2);
Assert.That(
() => testSlice,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is impossible to throw excepcion right? Do you want to check if the constructor throw or if the variable is null?

stream.WriteByte(0xCA);
stream.WriteByte(0xFE);

DataStream testSlice = stream.Slice(2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add just one more test for the base stream. Something like Assert.AreSame with testSlice.BaseStream and stream.BaseStream? so we know there isn't copies

@pleonex pleonex modified the milestones: vNext, Future Dec 23, 2020
@pleonex pleonex added the wip label Feb 24, 2021
@pleonex pleonex removed this from the vNext milestone Dec 5, 2021
@pleonex
Copy link
Member

pleonex commented Aug 21, 2023

This PR has been in WIP for 3 years.
Please put a comment or re-open the PR once it's ready for review with the latest comments.
Thanks for the contribution!

@pleonex pleonex closed this Aug 21, 2023
@pleonex pleonex mentioned this pull request Nov 28, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement method Slice in DataStream
2 participants