clean up byteorder.hh
byteorder.hh's "net::packed<T>" subclassed the basic unaligned<T> and added a "adjust_endianess" method. This was completely unnecessary: While ntoh's generic implementation indeed uses that method, we also have a specialized overload for ntoh(packed<T>), so the generic implementation would never be used for packed<T> anyway! So for net::packed<T> we don't need anything more than unaligned<T>, and can just make it an alias. As a bonus, the "hton" function will now work also on unaligned<T> (such as the result of the convenient unaligned_cast<>), not just on net::packed<T>. Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
This commit is contained in:
@@ -58,13 +58,9 @@ inline int32_t hton(int32_t x) { return htonl(x); }
|
||||
inline int64_t ntoh(int64_t x) { return ntohq(x); }
|
||||
inline int64_t hton(int64_t x) { return htonq(x); }
|
||||
|
||||
// Define net::packed<> using unaligned<> from unaligned.hh.
|
||||
template <typename T>
|
||||
struct packed : public unaligned<T> {
|
||||
using unaligned<T>::unaligned; // inherit constructors
|
||||
template <typename Adjuster>
|
||||
void adjust_endianness(Adjuster a) { a(this->raw); }
|
||||
} __attribute__((packed));
|
||||
// Deprecated alias net::packed<> for unaligned<> from unaligned.hh.
|
||||
// TODO: get rid of this alias.
|
||||
template <typename T> using packed = unaligned<T>;
|
||||
|
||||
template <typename T>
|
||||
inline T ntoh(const packed<T>& x) {
|
||||
|
||||
Reference in New Issue
Block a user