// dnlib: See LICENSE.txt for more info
using System;
using System.Text;
namespace dnlib.IO {
///
/// This class is used by a . The instance
/// verifies that all input are valid before calling any methods in this class.
/// This class is thread safe.
///
public abstract class DataStream {
///
/// Reads bytes
///
/// Offset of data
/// Destination pointer
/// Number of bytes to read
public unsafe abstract void ReadBytes(uint offset, void* destination, int length);
///
/// Reads bytes
///
/// Offset of data
/// Destination array
/// Destination index
/// Number of bytes to read
public abstract void ReadBytes(uint offset, byte[] destination, int destinationIndex, int length);
///
/// Reads a
///
/// Offset of data
///
public abstract byte ReadByte(uint offset);
///
/// Reads a
///
/// Offset of data
///
public virtual sbyte ReadSByte(uint offset) => (sbyte)ReadByte(offset);
///
/// Reads a 1-byte-long
///
/// Offset of data
///
public virtual bool ReadBoolean(uint offset) => ReadByte(offset) != 0;
///
/// Reads a
///
/// Offset of data
///
public abstract ushort ReadUInt16(uint offset);
///
/// Reads a
///
/// Offset of data
///
public virtual short ReadInt16(uint offset) => (short)ReadUInt16(offset);
///
/// Reads a 2-byte-long
///
/// Offset of data
///
public virtual char ReadChar(uint offset) => (char)ReadUInt16(offset);
///
/// Reads a
///
/// Offset of data
///
public abstract uint ReadUInt32(uint offset);
///
/// Reads a
///
/// Offset of data
///
public virtual int ReadInt32(uint offset) => (int)ReadUInt32(offset);
///
/// Reads a
///
/// Offset of data
///
public abstract ulong ReadUInt64(uint offset);
///
/// Reads a
///
/// Offset of data
///
public virtual long ReadInt64(uint offset) => (long)ReadUInt64(offset);
///
/// Reads a
///
/// Offset of data
///
public abstract float ReadSingle(uint offset);
///
/// Reads a
///
/// Offset of data
///
public abstract double ReadDouble(uint offset);
///
/// Reads a
///
/// Offset of data
///
public virtual Guid ReadGuid(uint offset) =>
new Guid(ReadUInt32(offset), ReadUInt16(offset + 4), ReadUInt16(offset + 6),
ReadByte(offset + 8), ReadByte(offset + 9), ReadByte(offset + 10), ReadByte(offset + 11),
ReadByte(offset + 12), ReadByte(offset + 13), ReadByte(offset + 14), ReadByte(offset + 15));
///
/// Reads a
///
/// Offset of data
///
public virtual decimal ReadDecimal(uint offset) {
int lo = ReadInt32(offset);
int mid = ReadInt32(offset + 4);
int hi = ReadInt32(offset + 8);
int flags = ReadInt32(offset + 12);
byte scale = (byte)(flags >> 16);
bool isNegative = (flags & 0x80000000) != 0;
return new decimal(lo, mid, hi, isNegative, scale);
}
///
/// Reads a UTF-16 encoded
///
/// Offset of data
/// Number of characters to read
///
public abstract string ReadUtf16String(uint offset, int chars);
///
/// Reads a string
///
/// Offset of data
/// Length of string in bytes
/// Encoding
///
public abstract string ReadString(uint offset, int length, Encoding encoding);
///
/// Gets the data offset of a byte or returns false if the byte wasn't found
///
/// Offset of data
/// End offset of data (not inclusive)
/// Byte value to search for
/// Offset of the byte if found
///
public abstract bool TryGetOffsetOf(uint offset, uint endOffset, byte value, out uint valueOffset);
}
}