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

@@ -150,7 +150,7 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
var block = default(VocBlock);
try
{
block.Code = stream.ReadByte();
block.Code = stream.ReadUInt8();
block.Length = 0;
}
catch (EndOfStreamException)
@@ -162,9 +162,9 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
if (block.Code == 0 || block.Code > 9)
break;
block.Length = stream.ReadByte();
block.Length |= stream.ReadByte() << 8;
block.Length |= stream.ReadByte() << 16;
block.Length = stream.ReadUInt8();
block.Length |= stream.ReadUInt8() << 8;
block.Length |= stream.ReadUInt8() << 16;
var skip = 0;
switch (block.Code)
@@ -174,9 +174,9 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
{
if (block.Length < 2)
throw new InvalidDataException("Invalid sound data block length in voc file");
var freqDiv = stream.ReadByte();
var freqDiv = stream.ReadUInt8();
block.SampleBlock.Rate = GetSampleRateFromVocRate(freqDiv);
var codec = stream.ReadByte();
var codec = stream.ReadUInt8();
if (codec != 0)
throw new InvalidDataException("Unhandled codec used in voc file");
skip = block.Length - 2;
@@ -205,7 +205,7 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
throw new InvalidDataException("Invalid silence block length in voc file");
block.SampleBlock.Offset = 0;
block.SampleBlock.Samples = stream.ReadUInt16() + 1;
var freqDiv = stream.ReadByte();
var freqDiv = stream.ReadUInt8();
block.SampleBlock.Rate = GetSampleRateFromVocRate(freqDiv);
break;
}
@@ -231,10 +231,10 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
int freqDiv = stream.ReadUInt16();
if (freqDiv == 65536)
throw new InvalidDataException("Invalid frequency divisor 65536 in voc file");
var codec = stream.ReadByte();
var codec = stream.ReadUInt8();
if (codec != 0)
throw new InvalidDataException("Unhandled codec used in voc file");
var channels = stream.ReadByte() + 1;
var channels = stream.ReadUInt8() + 1;
if (channels != 1)
throw new InvalidDataException("Unhandled number of channels in voc file");
block.SampleBlock.Offset = 0;