diff options
author | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2022-11-04 09:54:34 +0300 |
---|---|---|
committer | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2022-11-04 09:57:58 +0300 |
commit | bc05122b12da25b30f011d5ef6a2277863413b50 (patch) | |
tree | 97f3e5500983e64089e22223a12bc3bd9e0dc19f /FdsBlockFileData.cs | |
parent | a84c08415c43dad08c73e23f75e8d2cdd99174a9 (diff) |
Comments and minor changes
Diffstat (limited to 'FdsBlockFileData.cs')
-rw-r--r-- | FdsBlockFileData.cs | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/FdsBlockFileData.cs b/FdsBlockFileData.cs index 40f6e37..8ec31b4 100644 --- a/FdsBlockFileData.cs +++ b/FdsBlockFileData.cs @@ -4,9 +4,15 @@ using System.Linq; namespace com.clusterrr.Famicom.Containers
{
+ /// <summary>
+ /// File data FDS block (block type 4)
+ /// </summary>
public class FdsBlockFileData : IFdsBlock, IEquatable<FdsBlockFileData>
{
private byte blockType = 4;
+ /// <summary>
+ /// Valid block type ID
+ /// </summary>
public byte ValidTypeID { get => 4; }
/// <summary>
/// True if block type ID is valid
@@ -14,6 +20,9 @@ namespace com.clusterrr.Famicom.Containers public bool IsValid { get => blockType == ValidTypeID; }
private byte[] data = new byte[0];
+ /// <summary>
+ /// File data
+ /// </summary>
public IEnumerable<byte> Data
{
get => Array.AsReadOnly(data);
@@ -30,19 +39,33 @@ namespace com.clusterrr.Famicom.Containers /// </summary>
public bool EndOfHeadMeet { get; set; } = false;
+ /// <summary>
+ /// Length of the block
+ /// </summary>
public uint Length => (uint)(data.Length + 1);
- public static FdsBlockFileData FromBytes(byte[] rawData, int position = 0, int size = -1)
+ /// <summary>
+ /// Create FdsBlockFileData object from raw data
+ /// </summary>
+ /// <param name="data">Data</param>
+ /// <param name="offset">Offset</param>
+ /// <param name="length">Length</param>
+ /// <returns>FdsBlockFileData object</returns>
+ public static FdsBlockFileData FromBytes(byte[] data, int offset = 0, int length = -1)
{
var retobj = new FdsBlockFileData
{
- blockType = rawData[position],
- data = new byte[size < 0 ? rawData.Length - position - 1 : size - 1]
+ blockType = data[offset],
+ data = new byte[length < 0 ? data.Length - offset - 1 : length - 1]
};
- Array.Copy(rawData, position + 1, retobj.data, 0, retobj.data.Length);
+ Array.Copy(data, offset + 1, retobj.data, 0, retobj.data.Length);
return retobj;
}
+ /// <summary>
+ /// Return raw data
+ /// </summary>
+ /// <returns>Data</returns>
public byte[] ToBytes()
{
var result = new List<byte>
@@ -53,8 +76,17 @@ namespace com.clusterrr.Famicom.Containers return result.ToArray();
}
+ /// <summary>
+ /// String representation
+ /// </summary>
+ /// <returns>Number of bytes as string</returns>
public override string ToString() => $"{data.Length} bytes";
+ /// <summary>
+ /// Equality comparer
+ /// </summary>
+ /// <param name="other">Other FdsBlockFileData object</param>
+ /// <returns>True if objects are equal</returns>
public bool Equals(FdsBlockFileData other)
{
return Enumerable.SequenceEqual(this.ToBytes(), other.ToBytes());
|