Skip to content

Commit

Permalink
Added nested regions
Browse files Browse the repository at this point in the history
  • Loading branch information
GreyCat committed Aug 9, 2016
1 parent 1498255 commit a5e9529
Showing 1 changed file with 68 additions and 36 deletions.
104 changes: 68 additions & 36 deletions KaitaiStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,49 +83,57 @@ public long Size

#region Integer types

#region Signed

/// <summary>
/// Read an unsigned byte from the stream
/// Read a signed byte from the stream
/// </summary>
/// <returns></returns>
public byte ReadU1()
public sbyte ReadS1()
{
return ReadByte();
return ReadSByte();
}

#region Big-endian

/// <summary>
/// Read a signed byte from the stream
/// Read a signed short from the stream (big endian)
/// </summary>
/// <returns></returns>
public sbyte ReadS1()
public short ReadS2be()
{
return ReadSByte();
return BitConverter.ToInt16(ReadBytesNormalisedBigEndian(2), 0);
}

/// <summary>
/// Read an unsigned short from the stream (little endian)
/// Read a signed int from the stream (big endian)
/// </summary>
/// <returns></returns>
public ushort ReadU2le()
public int ReadS4be()
{
return BitConverter.ToUInt16(ReadBytesNormalisedLittleEndian(2), 0);
return BitConverter.ToInt32(ReadBytesNormalisedBigEndian(4), 0);
}

/// <summary>
/// Read a signed short from the stream (little endian)
/// Read a signed long from the stream (big endian)
/// </summary>
/// <returns></returns>
public short ReadS2le()
public long ReadS8be()
{
return BitConverter.ToInt16(ReadBytesNormalisedLittleEndian(2), 0);
return BitConverter.ToInt64(ReadBytesNormalisedBigEndian(8), 0);
}

#endregion

#region Little-endian

/// <summary>
/// Read an unsigned int from the stream (little endian)
/// Read a signed short from the stream (little endian)
/// </summary>
/// <returns></returns>
public uint ReadU4le()
public short ReadS2le()
{
return BitConverter.ToUInt32(ReadBytesNormalisedLittleEndian(4), 0);
return BitConverter.ToInt16(ReadBytesNormalisedLittleEndian(2), 0);
}

/// <summary>
Expand All @@ -138,23 +146,31 @@ public int ReadS4le()
}

/// <summary>
/// Read an unsigned long from the stream (little endian)
/// Read a signed long from the stream (little endian)
/// </summary>
/// <returns></returns>
public ulong ReadU8le()
public long ReadS8le()
{
return BitConverter.ToUInt64(ReadBytesNormalisedLittleEndian(8), 0);
return BitConverter.ToInt64(ReadBytesNormalisedLittleEndian(8), 0);
}

#endregion

#endregion

#region Unsigned

/// <summary>
/// Read a signed long from the stream (little endian)
/// Read an unsigned byte from the stream
/// </summary>
/// <returns></returns>
public long ReadS8le()
public byte ReadU1()
{
return BitConverter.ToInt64(ReadBytesNormalisedLittleEndian(8), 0);
return ReadByte();
}

#region Big-endian

/// <summary>
/// Read an unsigned short from the stream (big endian)
/// </summary>
Expand All @@ -165,54 +181,64 @@ public ushort ReadU2be()
}

/// <summary>
/// Read a signed short from the stream (big endian)
/// Read an unsigned int from the stream (big endian)
/// </summary>
/// <returns></returns>
public short ReadS2be()
public uint ReadU4be()
{
return BitConverter.ToInt16(ReadBytesNormalisedBigEndian(2), 0);
return BitConverter.ToUInt32(ReadBytesNormalisedBigEndian(4), 0);
}

/// <summary>
/// Read an unsigned int from the stream (big endian)
/// Read an unsigned long from the stream (big endian)
/// </summary>
/// <returns></returns>
public uint ReadU4be()
public ulong ReadU8be()
{
return BitConverter.ToUInt32(ReadBytesNormalisedBigEndian(4), 0);
return BitConverter.ToUInt64(ReadBytesNormalisedBigEndian(8), 0);
}

#endregion

#region Little-endian

/// <summary>
/// Read a signed int from the stream (big endian)
/// Read an unsigned short from the stream (little endian)
/// </summary>
/// <returns></returns>
public int ReadS4be()
public ushort ReadU2le()
{
return BitConverter.ToInt32(ReadBytesNormalisedBigEndian(4), 0);
return BitConverter.ToUInt16(ReadBytesNormalisedLittleEndian(2), 0);
}

/// <summary>
/// Read an unsigned long from the stream (big endian)
/// Read an unsigned int from the stream (little endian)
/// </summary>
/// <returns></returns>
public ulong ReadU8be()
public uint ReadU4le()
{
return BitConverter.ToUInt64(ReadBytesNormalisedBigEndian(8), 0);
return BitConverter.ToUInt32(ReadBytesNormalisedLittleEndian(4), 0);
}

/// <summary>
/// Read a signed long from the stream (big endian)
/// Read an unsigned long from the stream (little endian)
/// </summary>
/// <returns></returns>
public long ReadS8be()
public ulong ReadU8le()
{
return BitConverter.ToInt64(ReadBytesNormalisedBigEndian(8), 0);
return BitConverter.ToUInt64(ReadBytesNormalisedLittleEndian(8), 0);
}

#endregion

#endregion

#endregion

#region Floating point types

#region Big-endian

/// <summary>
/// Read a single-precision floating point value from the stream (big endian)
/// </summary>
Expand All @@ -231,6 +257,10 @@ public double ReadF8be()
return BitConverter.ToDouble(ReadBytesNormalisedBigEndian(8), 0);
}

#endregion

#region Little-endian

/// <summary>
/// Read a single-precision floating point value from the stream (little endian)
/// </summary>
Expand All @@ -251,6 +281,8 @@ public double ReadF8le()

#endregion

#endregion

#region Byte arrays

/// <summary>
Expand Down

0 comments on commit a5e9529

Please sign in to comment.