unsigned int32を読み込む処理 ReadUInt32() の追跡
public uint ReadUInt32()
{
ReadInternal(buffer, 4);
return bitConverter.ToUInt32(buffer, 0);
}
public uint ToUInt32 (byte[] value, int startIndex)
{
return unchecked((uint) (CheckedFromBytes(value, startIndex, 4)));
}
long CheckedFromBytes(byte[] value, int startIndex, int bytesToConvert)
{
CheckByteArgument(value, startIndex, bytesToConvert);
return FromBytes(value, startIndex, bytesToConvert);
}
CheckByteArgument()は例外処理。
/// <summary>
/// Convert the given number of bytes from the given array, from the given start
/// position, into a long, using the bytes as the least significant part of the long.
/// By the time this is called, the arguments have been checked for validity.
/// </summary>
/// <param name="value">The bytes to convert</param>
/// <param name="startIndex">The index of the first byte to convert</param>
/// <param name="bytesToConvert">The number of bytes to use in the conversion</param>
/// <returns>The converted number</returns>
protected abstract long FromBytes(byte[] value, int startIndex, int bytesToConvert);
#endregion
protected override long FromBytes(byte[] buffer, int startIndex, int bytesToConvert)
{
long ret = 0;
for (int i=0; i < bytesToConvert; i++)
{
ret = unchecked((ret << 8) | buffer[startIndex+bytesToConvert-1-i]);
}
return ret;
}