Prefer ReadUInt8 over ReadByte.

The former will throw when the end of the stream is reached, rather than requiring the caller to check for -1.
This commit is contained in:
RoosterDragon
2020-10-18 11:35:21 +01:00
committed by abcdefg30
parent f5f2f58664
commit aac1bae899
10 changed files with 39 additions and 39 deletions

View File

@@ -18,13 +18,13 @@ using OpenRA.Primitives;
namespace OpenRA.Mods.Cnc.FileFormats
{
[Flags]
enum SoundFlags
enum SoundFlags : byte
{
Stereo = 0x1,
_16Bit = 0x2,
}
enum SoundFormat
enum SoundFormat : byte
{
WestwoodCompressed = 1,
ImaAdpcm = 99,
@@ -59,12 +59,12 @@ namespace OpenRA.Mods.Cnc.FileFormats
sampleRate = s.ReadUInt16();
var dataSize = s.ReadInt32();
var outputSize = s.ReadInt32();
var audioFlags = (SoundFlags)s.ReadByte();
var audioFlags = (SoundFlags)s.ReadUInt8();
sampleBits = (audioFlags & SoundFlags._16Bit) == 0 ? 8 : 16;
channels = (audioFlags & SoundFlags.Stereo) == 0 ? 1 : 2;
lengthInSeconds = (float)(outputSize * 8) / (channels * sampleBits * sampleRate);
var readFormat = s.ReadByte();
var readFormat = s.ReadUInt8();
if (!Enum.IsDefined(typeof(SoundFormat), readFormat))
return false;