Treat request bytes as an unsigned type
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
913b6ee15b
commit
34335045ca
@ -1,11 +1,11 @@
|
||||
#include "network.hpp"
|
||||
|
||||
namespace sk {
|
||||
uint32_t read_uint32(const char *buffer) { return static_cast<uint32_t>(buffer[3]) | static_cast<uint32_t>(buffer[2]) << 8 | static_cast<uint32_t>(buffer[1]) << 16 | static_cast<uint32_t>(buffer[0]) << 24; }
|
||||
void write_uint32(char *buffer, uint32_t value) {
|
||||
buffer[0] = static_cast<char>(value >> 24);
|
||||
buffer[1] = static_cast<char>(value >> 16);
|
||||
buffer[2] = static_cast<char>(value >> 8);
|
||||
buffer[3] = static_cast<char>(value);
|
||||
uint32_t read_uint32(const std::byte *buffer) { return static_cast<uint32_t>(buffer[3]) | static_cast<uint32_t>(buffer[2]) << 8 | static_cast<uint32_t>(buffer[1]) << 16 | static_cast<uint32_t>(buffer[0]) << 24; }
|
||||
void write_uint32(std::byte *buffer, uint32_t value) {
|
||||
buffer[0] = static_cast<std::byte>(value >> 24);
|
||||
buffer[1] = static_cast<std::byte>(value >> 16);
|
||||
buffer[2] = static_cast<std::byte>(value >> 8);
|
||||
buffer[3] = static_cast<std::byte>(value);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace sk {
|
||||
uint32_t read_uint32(const char *buffer);
|
||||
void write_uint32(char *buffer, uint32_t value);
|
||||
uint32_t read_uint32(const std::byte *buffer);
|
||||
void write_uint32(std::byte *buffer, uint32_t value);
|
||||
}
|
||||
|
Loading…
Reference in new issue