mirror of
https://github.com/esphome/esphome.git
synced 2025-09-12 16:22:22 +01:00
use `encode_uintXX
` (#8847)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -192,15 +192,15 @@ bool random_bytes(uint8_t *data, size_t len);
|
||||
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb) {
|
||||
return (static_cast<uint16_t>(msb) << 8) | (static_cast<uint16_t>(lsb));
|
||||
}
|
||||
/// Encode a 24-bit value given three bytes in most to least significant byte order.
|
||||
constexpr uint32_t encode_uint24(uint8_t byte1, uint8_t byte2, uint8_t byte3) {
|
||||
return (static_cast<uint32_t>(byte1) << 16) | (static_cast<uint32_t>(byte2) << 8) | (static_cast<uint32_t>(byte3));
|
||||
}
|
||||
/// Encode a 32-bit value given four bytes in most to least significant byte order.
|
||||
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4) {
|
||||
return (static_cast<uint32_t>(byte1) << 24) | (static_cast<uint32_t>(byte2) << 16) |
|
||||
(static_cast<uint32_t>(byte3) << 8) | (static_cast<uint32_t>(byte4));
|
||||
}
|
||||
/// Encode a 24-bit value given three bytes in most to least significant byte order.
|
||||
constexpr uint32_t encode_uint24(uint8_t byte1, uint8_t byte2, uint8_t byte3) {
|
||||
return ((static_cast<uint32_t>(byte1) << 16) | (static_cast<uint32_t>(byte2) << 8) | (static_cast<uint32_t>(byte3)));
|
||||
}
|
||||
|
||||
/// Encode a value from its constituent bytes (from most to least significant) in an array with length sizeof(T).
|
||||
template<typename T, enable_if_t<std::is_unsigned<T>::value, int> = 0>
|
||||
|
Reference in New Issue
Block a user