-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 parent
7f9b6ee
commit 7e52e01
Showing
26 changed files
with
3,482 additions
and
2,216 deletions.
There are no files selected for viewing
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
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
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
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
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,85 @@ | ||
// ---------------------------------------------------------------------- | ||
// @Namespace : NewtonVgo | ||
// @Class : VgoReadChunk | ||
// ---------------------------------------------------------------------- | ||
#nullable enable | ||
namespace NewtonVgo | ||
{ | ||
/// <summary> | ||
/// VGO Read Chunk | ||
/// </summary> | ||
public class VgoReadChunk | ||
{ | ||
#region Fields | ||
|
||
/// <summary>The chunk type ID.</summary> | ||
public readonly VgoChunkTypeID _TypeId; | ||
|
||
/// <summary>Length of the chunk data.</summary> | ||
public readonly uint _DataLength; | ||
|
||
/// <summary>The chunk data.</summary> | ||
public readonly byte[] _ChunkData; | ||
|
||
#endregion | ||
|
||
#region Properties | ||
|
||
/// <summary>The chunk type ID.</summary> | ||
public VgoChunkTypeID TypeId => _TypeId; | ||
|
||
/// <summary>Length of the chunk data.</summary> | ||
public uint DataLength => _DataLength; | ||
|
||
/// <summary>The chunk data.</summary> | ||
public byte[] ChunkData => _ChunkData; | ||
|
||
#endregion | ||
|
||
#region Constructors | ||
|
||
/// <summary> | ||
/// Create a new instance of VgoReadChunk. | ||
/// </summary> | ||
/// <param name="chunkTypeId">The chunk type ID.</param> | ||
/// <param name="chunkData">The chunk data.</param> | ||
public VgoReadChunk(VgoChunkTypeID chunkTypeId, byte[] chunkData) | ||
{ | ||
_TypeId = chunkTypeId; | ||
|
||
_DataLength = (uint)chunkData.Length; | ||
|
||
_ChunkData = chunkData; | ||
} | ||
|
||
/// <summary> | ||
/// Create a new instance of VgoReadChunk. | ||
/// </summary> | ||
/// <param name="chunkTypeId">The chunk type ID.</param> | ||
/// <param name="chunkDataLength">Length of the chunk data.</param> | ||
/// <param name="chunkData">The chunk data.</param> | ||
public VgoReadChunk(VgoChunkTypeID chunkTypeId, uint chunkDataLength, byte[] chunkData) | ||
{ | ||
_TypeId = chunkTypeId; | ||
|
||
_DataLength = chunkDataLength; | ||
|
||
_ChunkData = chunkData; | ||
} | ||
|
||
#endregion | ||
|
||
#region Public Methods | ||
|
||
/// <summary> | ||
/// Returns a string that represents the current object. | ||
/// </summary> | ||
/// <returns>A string that represents the current object.</returns> | ||
public override string ToString() | ||
{ | ||
return TypeId.ToString(); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...Runtime/Porters/VgoImporter.Async.cs.meta → ...onVgo/Runtime/Chunks/VgoReadChunk.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,103 @@ | ||
// ---------------------------------------------------------------------- | ||
// @Namespace : NewtonVgo | ||
// @Class : StreamExtensions | ||
// ---------------------------------------------------------------------- | ||
#nullable enable | ||
namespace NewtonVgo | ||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
using System.Threading; | ||
using System.IO; | ||
|
||
/// <summary> | ||
/// Stream Extensions | ||
/// </summary> | ||
public static class StreamExtensions | ||
{ | ||
/// <summary> | ||
/// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read. | ||
/// </summary> | ||
/// <param name="stream">The stream.</param> | ||
/// <param name="count">The number of bytes to read.</param> | ||
/// <returns>An array of bytes.</returns> | ||
public static byte[] ReadBytes(this Stream stream, int count) | ||
{ | ||
if (count < 0) | ||
{ | ||
ThrowHelper.ThrowArgumentOutOfRangeException(nameof(count)); | ||
} | ||
|
||
if (count == 0) | ||
{ | ||
return Array.Empty<byte>(); | ||
} | ||
|
||
byte[] buffer = new byte[count]; | ||
|
||
int numBytesToRead = count; | ||
|
||
int numBytesRead = 0; | ||
|
||
do | ||
{ | ||
int n = stream.Read(buffer, offset: numBytesRead, count: numBytesToRead); | ||
|
||
numBytesRead += n; | ||
|
||
numBytesToRead -= n; | ||
} | ||
while (numBytesToRead > 0); | ||
|
||
if (numBytesRead != count) | ||
{ | ||
ThrowHelper.ThrowIOException(); | ||
} | ||
|
||
return buffer; | ||
} | ||
|
||
/// <summary> | ||
/// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read. | ||
/// </summary> | ||
/// <param name="stream">The stream.</param> | ||
/// <param name="count">The number of bytes to read.</param> | ||
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param> | ||
/// <returns>An array of bytes.</returns> | ||
public static async Task<byte[]> ReadBytesAsync(this Stream stream, int count, CancellationToken cancellationToken) | ||
{ | ||
if (count < 0) | ||
{ | ||
ThrowHelper.ThrowArgumentOutOfRangeException(nameof(count)); | ||
} | ||
|
||
if (count == 0) | ||
{ | ||
return Array.Empty<byte>(); | ||
} | ||
|
||
byte[] buffer = new byte[count]; | ||
|
||
int numBytesToRead = count; | ||
|
||
int numBytesRead = 0; | ||
|
||
do | ||
{ | ||
int n = await stream.ReadAsync(buffer, offset: numBytesRead, count: numBytesToRead, cancellationToken); | ||
|
||
numBytesRead += n; | ||
|
||
numBytesToRead -= n; | ||
} | ||
while (numBytesToRead > 0); | ||
|
||
if (numBytesRead != count) | ||
{ | ||
ThrowHelper.ThrowIOException(); | ||
} | ||
|
||
return buffer; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.