using System;
using System.IO;
using System.Linq;
namespace com.clusterrr.Famicom.Containers
{
///
/// File amount FDS block (block type 2)
///
public class FdsBlockFileAmount : IFdsBlock, IEquatable
{
private byte blockType = 2;
///
/// Valid block type ID
///
public byte ValidTypeID { get => 2; }
///
/// True if block type ID is valid
///
public bool IsValid { get => blockType == ValidTypeID; }
private byte fileAmount;
///
/// Amount of files
///
public byte FileAmount { get => fileAmount; set => fileAmount = value; }
///
/// Length of the block
///
public uint Length { get => 2; }
///
/// Create FdsBlockFileAmount object from raw data
///
/// Data
/// Data offset
/// FdsBlockFileAmount object
public static FdsBlockFileAmount FromBytes(byte[] data, int offset = 0)
{
if (data.Length - offset < 2)
throw new InvalidDataException("Not enough data to fill FdsBlockFileAmount class. Array length from position: " + (data.Length - offset) + ", struct length: 2");
return new FdsBlockFileAmount
{
blockType = data[offset],
fileAmount = data[offset + 1]
};
}
///
/// Returns raw data
///
/// Data
public byte[] ToBytes() => new byte[] { blockType, fileAmount };
///
/// String representation
///
/// File amount as string
public override string ToString() => $"{FileAmount}";
///
/// Equality comparer
///
/// Other FdsBlockFileAmount object
/// True if objects are equal
public bool Equals(FdsBlockFileAmount other)
{
return Enumerable.SequenceEqual(this.ToBytes(), other.ToBytes());
}
}
}