Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyoo0812 committed Oct 25, 2023
1 parent 2099bc4 commit 05144b1
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions extend/lcodec/src/websocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ using namespace luakit;

namespace lcodec {

inline uint64_t byteswap8(uint64_t const net) {
uint8_t data[8] = {};
memcpy(&data, &net, sizeof(data));
inline uint64_t byteswap8(uint64_t const u64) {
uint8_t* data = (uint8_t*) &u64;
return ((uint64_t)data[7] << 0)
| ((uint64_t)data[6] << 8)
| ((uint64_t)data[5] << 16)
Expand All @@ -20,9 +19,8 @@ namespace lcodec {
| ((uint64_t)data[0] << 56);
}

inline uint16_t byteswap2(uint16_t const net) {
uint8_t data[2] = {};
memcpy(&data, &net, sizeof(data));
inline uint16_t byteswap2(uint16_t const u16) {
uint8_t* data = (uint8_t*)&u16;
return ((uint16_t)data[1] << 0)
| ((uint16_t)data[0] << 8);
}
Expand Down

0 comments on commit 05144b1

Please sign in to comment.