MySql.Data.MySqlClient.MySqlPacket.Read3ByteInt C# (CSharp) Method

Read3ByteInt() public method

public Read3ByteInt ( ) : int
return int
    public int Read3ByteInt()
    {
      int value = 0;

      int pos = (int)buffer.Position;
      byte[] bits = buffer.GetBuffer();
      int shift = 0;

      for (int i = 0; i < 3; i++)
      {
        value |= (int)(bits[pos++] << shift);
        shift += 8;
      }
      buffer.Position += 3;
      return value;
    }

Usage Example

    IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal)
    {

      if (nullVal) return new MySqlDateTime(type, true);

      if (length >= 0)
      {
        var value = packet.ReadString(length);
        return ParseMySql(value);
      }

      long bufLength = packet.ReadByte();
      int year = 0, month = 0, day = 0;
      int hour = 0, minute = 0, second = 0, millisecond = 0;
      if (bufLength >= 4)
      {
        year = packet.ReadInteger(2);
        month = packet.ReadByte();
        day = packet.ReadByte();
      }

      if (bufLength > 4)
      {
        hour = packet.ReadByte();
        minute = packet.ReadByte();
        second = packet.ReadByte();
      }

      if (bufLength > 7)
      {
        millisecond = packet.Read3ByteInt();
        packet.ReadByte();
      }

      return new MySqlDateTime(type, year, month, day, hour, minute, second, millisecond);
    }