mirror of
https://github.com/rvtr/ctr_test_tools.git
synced 2025-06-19 00:55:31 -04:00

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_test_tools@11 6b0af911-cb57-b745-895f-eec5701120e1
82 lines
2.2 KiB
C#
82 lines
2.2 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
|
|
namespace TwlBackupBlock
|
|
{
|
|
/// <summary>
|
|
/// バイト単位でアクセスする機能だけを持ったデータ本体です。
|
|
/// </summary>
|
|
public class Body : AbstractBody
|
|
{
|
|
private byte[] data;
|
|
|
|
/// <summary>
|
|
/// 指定したデータ本体をもとに、Bodyクラスの新しいインスタンスを初期化します。
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
public Body(byte[] data)
|
|
{
|
|
if (data == null)
|
|
{
|
|
throw new ArgumentNullException("data");
|
|
}
|
|
this.data = (byte[])data.Clone();
|
|
}
|
|
|
|
public override byte this[int index]
|
|
{
|
|
get
|
|
{
|
|
if (index < 0 || index >= data.Length)
|
|
{
|
|
throw new ArgumentOutOfRangeException("index");
|
|
}
|
|
return data[index];
|
|
}
|
|
set
|
|
{
|
|
if (index < 0 || index >= data.Length)
|
|
{
|
|
throw new ArgumentOutOfRangeException("index");
|
|
}
|
|
data[index] = value;
|
|
}
|
|
}
|
|
|
|
public override int Length
|
|
{
|
|
get
|
|
{
|
|
Debug.Assert(data != null);
|
|
return data.Length;
|
|
}
|
|
}
|
|
|
|
public override byte[] GetBytes()
|
|
{
|
|
Debug.Assert(data != null);
|
|
return (byte[])data.Clone();
|
|
}
|
|
|
|
public override void SetBytes(byte[] bytes)
|
|
{
|
|
Debug.Assert(data != null);
|
|
if (bytes == null)
|
|
{
|
|
throw new ArgumentNullException("bytes");
|
|
}
|
|
if (bytes.Length != data.Length)
|
|
{
|
|
string message = string.Format("bytes.Length != {0} (bytes.Length:{1})", data.Length, bytes.Length);
|
|
throw new ArgumentException("bytes", message);
|
|
}
|
|
bytes.CopyTo(data, 0);
|
|
}
|
|
|
|
public override object Clone()
|
|
{
|
|
return new Body(GetBytes());
|
|
}
|
|
}
|
|
}
|