Skip to content

Commit

Permalink
Fix name conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
uchenily committed Jun 8, 2024
1 parent 458a38d commit af5228d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 44 deletions.
4 changes: 2 additions & 2 deletions uvio/codec/fixed_length.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ class FixedLength32Codec : public Codec<FixedLength32Codec> {
}
value |= static_cast<uint32_t>(bytes[0] & 0xFF) << (i * 8);
}
value = net::ntohl(value);
value = net::byteorder::ntohl(value);
co_return value;
}

template <typename Writer>
auto encode_length(uint32_t value, Writer &writer) -> Task<Result<void>> {
std::array<char, 1> bytes{};
value = net::htonl(value);
value = net::byteorder::htonl(value);
for (int i = 0; i < fixed_length_bytes; ++i) {
bytes[0] = static_cast<char>((value & 0xFF) | 0x00);
if (auto ret = co_await writer.write(bytes); !ret) {
Expand Down
4 changes: 2 additions & 2 deletions uvio/codec/length_delimited.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class LengthDelimitedCodec : public Codec<LengthDelimitedCodec> {
}
value |= static_cast<uint64_t>(bytes[0] & 0x7F) << (i * 7);
if ((bytes[0] & 0x80) == 0) {
value = net::ntohll(value);
value = net::byteorder::ntohll(value);
co_return value;
}
}
Expand All @@ -89,7 +89,7 @@ class LengthDelimitedCodec : public Codec<LengthDelimitedCodec> {
auto encode_length(uint64_t value, Writer &writer) -> Task<Result<void>> {
// Encodes value in varint format and writes the result by writer
std::array<char, 1> bytes;
value = net::htonll(value);
value = net::byteorder::htonll(value);
do {
bytes[0] = (value & 0x7F) | (((value >> 7) == 0) ? 0x00 : 0x80);
if (auto ret = co_await writer.write(bytes); !ret) {
Expand Down
8 changes: 4 additions & 4 deletions uvio/codec/websocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class WebsocketCodec : public Codec<WebsocketCodec> {
if (length == 126) {
co_await reader.read_exact(buf);
length = buf[1] << 8 | buf[0];
length = net::ntohs(length);
length = net::byteorder::ntohs(length);
} else if (length == 127) {
co_await reader.read_exact(
{reinterpret_cast<char *>(buf8.data()), buf8.size()});
Expand All @@ -39,7 +39,7 @@ class WebsocketCodec : public Codec<WebsocketCodec> {
| static_cast<uint64_t>(buf8[5]) << 40
| static_cast<uint64_t>(buf8[6]) << 48
| static_cast<uint64_t>(buf8[7]) << 56;
length = net::ntohll(length);
length = net::byteorder::ntohll(length);
}
LOG_DEBUG("payload length: {}", length);

Expand Down Expand Up @@ -67,13 +67,13 @@ class WebsocketCodec : public Codec<WebsocketCodec> {
buf[1] |= length;
co_await writer.write({reinterpret_cast<char *>(buf.data()), 2});
} else if (length < 65536) {
length = net::htons(length);
length = net::byteorder::htons(length);
buf[1] |= 126;
buf[2] = (length >> 0) & 0xFF;
buf[3] = (length >> 8) & 0xFF;
co_await writer.write({reinterpret_cast<char *>(buf.data()), 4});
} else {
length = net::htonll(length);
length = net::byteorder::htonll(length);
buf[1] |= 127;
buf[2] = (length >> 0) & 0xFF;
buf[3] = (length >> 8) & 0xFF;
Expand Down
75 changes: 39 additions & 36 deletions uvio/net/endian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,49 @@

namespace uvio::net {

class byteorder {
public:
#if __BYTE_ORDER == __LITTLE_ENDIAN
static inline auto htonll(uint64_t x) -> uint64_t {
return __bswap_64(x);
}
static inline auto ntohll(uint64_t x) -> uint64_t {
return __bswap_64(x);
}
static inline auto htonl(uint32_t x) -> uint32_t {
return __bswap_32(x);
}
static inline auto ntohl(uint32_t x) -> uint32_t {
return __bswap_32(x);
}
static inline auto htons(uint16_t x) -> uint16_t {
return __bswap_16(x);
}
static inline auto ntohs(uint16_t x) -> uint16_t {
return __bswap_16(x);
}
static inline auto htonll(uint64_t x) -> uint64_t {
return __bswap_64(x);
}
static inline auto ntohll(uint64_t x) -> uint64_t {
return __bswap_64(x);
}
static inline auto htonl(uint32_t x) -> uint32_t {
return __bswap_32(x);
}
static inline auto ntohl(uint32_t x) -> uint32_t {
return __bswap_32(x);
}
static inline auto htons(uint16_t x) -> uint16_t {
return __bswap_16(x);
}
static inline auto ntohs(uint16_t x) -> uint16_t {
return __bswap_16(x);
}
#elif __BYTE_ORDER == __BIG_ENDIAN
static inline auto htonll(uint64_t x) -> uint64_t {
return x;
}
static inline auto ntohll(uint64_t x) -> uint64_t {
return x;
}
static inline auto htonl(uint32_t x) -> uint32_t {
return x;
}
static inline auto ntohl(uint32_t x) -> uint32_t {
return x;
}
static inline auto htons(uint16_t x) -> uint16_t {
return x;
}
static inline auto ntohs(uint16_t x) -> uint16_t {
return x;
}
static inline auto htonll(uint64_t x) -> uint64_t {
return x;
}
static inline auto ntohll(uint64_t x) -> uint64_t {
return x;
}
static inline auto htonl(uint32_t x) -> uint32_t {
return x;
}
static inline auto ntohl(uint32_t x) -> uint32_t {
return x;
}
static inline auto htons(uint16_t x) -> uint16_t {
return x;
}
static inline auto ntohs(uint16_t x) -> uint16_t {
return x;
}
#else
#error "__BYTE_ORDER not defined!"
#endif
};

} // namespace uvio::net

0 comments on commit af5228d

Please sign in to comment.