LoginSignup
0
0

More than 5 years have passed since last update.

elfsharp > ReadUInt32()の構造

Last updated at Posted at 2015-08-22

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;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0