-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FdsBlockFileAmount.cs
72 lines (65 loc) · 2.38 KB
/
FdsBlockFileAmount.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.IO;
using System.Linq;
namespace com.clusterrr.Famicom.Containers
{
/// <summary>
/// File amount FDS block (block type 2)
/// </summary>
public class FdsBlockFileAmount : IFdsBlock, IEquatable<FdsBlockFileAmount>
{
private byte blockType = 2;
/// <summary>
/// Valid block type ID
/// </summary>
public byte ValidTypeID { get => 2; }
/// <summary>
/// True if block type ID is valid
/// </summary>
public bool IsValid { get => blockType == ValidTypeID; }
private byte fileAmount;
/// <summary>
/// Amount of files
/// </summary>
public byte FileAmount { get => fileAmount; set => fileAmount = value; }
/// <summary>
/// Length of the block
/// </summary>
public uint Length { get => 2; }
/// <summary>
/// Create FdsBlockFileAmount object from raw data
/// </summary>
/// <param name="data">Data</param>
/// <param name="offset">Data offset</param>
/// <returns>FdsBlockFileAmount object</returns>
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]
};
}
/// <summary>
/// Returns raw data
/// </summary>
/// <returns>Data</returns>
public byte[] ToBytes() => new byte[] { blockType, fileAmount };
/// <summary>
/// String representation
/// </summary>
/// <returns>File amount as string</returns>
public override string ToString() => $"{FileAmount}";
/// <summary>
/// Equality comparer
/// </summary>
/// <param name="other">Other FdsBlockFileAmount object</param>
/// <returns>True if objects are equal</returns>
public bool Equals(FdsBlockFileAmount other)
{
return Enumerable.SequenceEqual(this.ToBytes(), other.ToBytes());
}
}
}