-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
613 additions
and
1 deletion.
There are no files selected for viewing
161 changes: 161 additions & 0 deletions
161
Kaitai.Struct.Runtime.Async/Interface/IKaitaiAsyncStream.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace Kaitai.Async | ||
{ | ||
public interface IKaitaiAsyncStream : IKaitaiStreamBase | ||
{ | ||
/// <summary> | ||
/// Seek to a specific position from the beginning of the stream | ||
/// </summary> | ||
/// <param name="position">The position to seek to</param> | ||
Task SeekAsync(long position); | ||
|
||
/// <summary> | ||
/// Read a signed byte from the stream | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<sbyte> ReadS1Async(); | ||
|
||
/// <summary> | ||
/// Read a signed short from the stream (big endian) | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<short> ReadS2beAsync(); | ||
|
||
/// <summary> | ||
/// Read a signed int from the stream (big endian) | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<int> ReadS4beAsync(); | ||
|
||
/// <summary> | ||
/// Read a signed long from the stream (big endian) | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<long> ReadS8beAsync(); | ||
|
||
/// <summary> | ||
/// Read a signed short from the stream (little endian) | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<short> ReadS2leAsync(); | ||
|
||
/// <summary> | ||
/// Read a signed int from the stream (little endian) | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<int> ReadS4leAsync(); | ||
|
||
/// <summary> | ||
/// Read a signed long from the stream (little endian) | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<long> ReadS8leAsync(); | ||
|
||
/// <summary> | ||
/// Read an unsigned byte from the stream | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<byte> ReadU1Async(); | ||
|
||
/// <summary> | ||
/// Read an unsigned short from the stream (big endian) | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<ushort> ReadU2beAsync(); | ||
|
||
/// <summary> | ||
/// Read an unsigned int from the stream (big endian) | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<uint> ReadU4beAsync(); | ||
|
||
/// <summary> | ||
/// Read an unsigned long from the stream (big endian) | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<ulong> ReadU8beAsync(); | ||
|
||
/// <summary> | ||
/// Read an unsigned short from the stream (little endian) | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<ushort> ReadU2leAsync(); | ||
|
||
/// <summary> | ||
/// Read an unsigned int from the stream (little endian) | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<uint> ReadU4leAsync(); | ||
|
||
/// <summary> | ||
/// Read an unsigned long from the stream (little endian) | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<ulong> ReadU8leAsync(); | ||
|
||
/// <summary> | ||
/// Read a single-precision floating point value from the stream (big endian) | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<float> ReadF4beAsync(); | ||
|
||
/// <summary> | ||
/// Read a double-precision floating point value from the stream (big endian) | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<double> ReadF8beAsync(); | ||
|
||
/// <summary> | ||
/// Read a single-precision floating point value from the stream (little endian) | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<float> ReadF4leAsync(); | ||
|
||
/// <summary> | ||
/// Read a double-precision floating point value from the stream (little endian) | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<double> ReadF8leAsync(); | ||
|
||
Task<ulong> ReadBitsIntAsync(int n); | ||
Task<ulong> ReadBitsIntLeAsync(int n); | ||
|
||
/// <summary> | ||
/// Read a fixed number of bytes from the stream | ||
/// </summary> | ||
/// <param name="count">The number of bytes to read</param> | ||
/// <returns></returns> | ||
Task<byte[]> ReadBytesAsync(long count); | ||
|
||
/// <summary> | ||
/// Read a fixed number of bytes from the stream | ||
/// </summary> | ||
/// <param name="count">The number of bytes to read</param> | ||
/// <returns></returns> | ||
Task<byte[]> ReadBytesAsync(ulong count); | ||
|
||
/// <summary> | ||
/// Read all the remaining bytes from the stream until the end is reached | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<byte[]> ReadBytesFullAsync(); | ||
|
||
/// <summary> | ||
/// Read a terminated string from the stream | ||
/// </summary> | ||
/// <param name="terminator">The string terminator value</param> | ||
/// <param name="includeTerminator">True to include the terminator in the returned string</param> | ||
/// <param name="consumeTerminator">True to consume the terminator byte before returning</param> | ||
/// <param name="eosError">True to throw an error when the EOS was reached before the terminator</param> | ||
/// <returns></returns> | ||
Task<byte[]> ReadBytesTermAsync(byte terminator, bool includeTerminator, bool consumeTerminator, bool eosError); | ||
|
||
/// <summary> | ||
/// Read a specific set of bytes and assert that they are the same as an expected result | ||
/// </summary> | ||
/// <param name="expected">The expected result</param> | ||
/// <returns></returns> | ||
Task<byte[]> EnsureFixedContentsAsync(byte[] expected); | ||
} | ||
} |
11 changes: 10 additions & 1 deletion
11
Kaitai.Struct.Runtime.Async/Kaitai.Struct.Runtime.Async.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<RootNamespace>Kaitai.Async</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Kaitai.Struct.Runtime\Kaitai.Struct.Runtime.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Overby.Extensions.AsyncBinaryReaderWriter" Version="1.0.39" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Kaitai.Async | ||
{ | ||
public abstract class KaitaiStruct | ||
{ | ||
protected readonly IKaitaiAsyncStream m_io; | ||
|
||
protected KaitaiStruct(IKaitaiAsyncStream kaitaiStream) | ||
{ | ||
m_io = kaitaiStream; | ||
} | ||
|
||
// ReSharper disable once InconsistentNaming | ||
public IKaitaiAsyncStream M_Io => m_io; | ||
} | ||
} |
Oops, something went wrong.