Skip to content

Commit

Permalink
Added some methods for returning a value from a subread.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeltyPlayer committed Jun 27, 2023
1 parent e87f3f4 commit 69f23b1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Schema/lib/system/io/reader/EndianBinaryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using SubstreamSharp;

using static schema.binary.BinarySchemaStructureParser;

namespace System.IO {
public sealed partial class EndianBinaryReader : IEndianBinaryReader,
Expand Down Expand Up @@ -162,6 +163,30 @@ public void Subread(long position, Action<IEndianBinaryReader> subread) {
}


public T Subread<T>(long position,
int len,
Func<IEndianBinaryReader, T> subread) {
T value = default;

this.Subread(
position,
len,
ser => { value = subread(ser); });

return value!;
}

public T Subread<T>(long position, Func<IEndianBinaryReader, T> subread) {
T value = default;

this.Subread(
position,
ser => { value = subread(ser); });

return value!;
}


[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void Assert_<T>(T expectedValue, T actualValue) {
if (!expectedValue.Equals(actualValue)) {
Expand Down
9 changes: 9 additions & 0 deletions Schema/lib/system/io/reader/IEndianBinaryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@ public interface IEndianBinaryReader : IEndiannessStack, IDataReader {
T ReadNewAtOffset<T>(long position) where T : IBinaryDeserializable, new();
T[] ReadNewArrayAtOffset<T>(long position, int length) where T : IBinaryDeserializable, new();


void Subread(long position,
int len,
Action<IEndianBinaryReader> subread);

void Subread(long position, Action<IEndianBinaryReader> subread);


T Subread<T>(long position,
int len,
Func<IEndianBinaryReader, T> subread);

T Subread<T>(long position, Func<IEndianBinaryReader, T> subread);


byte[] ReadBytes(long count);
void ReadBytes(byte[] dst, int start, int length);
void ReadBytes(Span<byte> dst);
Expand Down

0 comments on commit 69f23b1

Please sign in to comment.