Commit 1aed2254 authored by salix5's avatar salix5 Committed by GitHub

simplify buffer read/write functions (#762)

parent d0531fdd
...@@ -12,7 +12,8 @@ inline void buffer_read_block(unsigned char*& p, void* dest, size_t size) { ...@@ -12,7 +12,8 @@ inline void buffer_read_block(unsigned char*& p, void* dest, size_t size) {
template<typename T> template<typename T>
inline T buffer_read(unsigned char*& p) { inline T buffer_read(unsigned char*& p) {
T ret{}; T ret{};
buffer_read_block(p, &ret, sizeof(T)); std::memcpy(&ret, p, sizeof(T));
p += sizeof(T);
return ret; return ret;
} }
...@@ -22,7 +23,8 @@ inline void buffer_write_block(unsigned char*& p, const void* src, size_t size) ...@@ -22,7 +23,8 @@ inline void buffer_write_block(unsigned char*& p, const void* src, size_t size)
} }
template<typename T> template<typename T>
inline void buffer_write(unsigned char*& p, T value) { inline void buffer_write(unsigned char*& p, T value) {
buffer_write_block(p, &value, sizeof(T)); std::memcpy(p, &value, sizeof(T));
p += sizeof(T);
} }
inline void vector_write_block(std::vector<unsigned char>& buffer, const void* src, size_t size) { inline void vector_write_block(std::vector<unsigned char>& buffer, const void* src, size_t size) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment