Mercurial > minori
diff include/core/byte_stream.h @ 369:47c9f8502269
*: clang-format all the things
I've edited the formatting a bit. Now pointer asterisks (and reference
ampersands) are on the variable instead of the type, as well as having
newlines for function braces (but nothing else)
author | Paper <paper@tflc.us> |
---|---|
date | Fri, 25 Jul 2025 10:16:02 -0400 |
parents | 99c961c91809 |
children |
line wrap: on
line diff
--- a/include/core/byte_stream.h Fri Jul 25 10:05:23 2025 -0400 +++ b/include/core/byte_stream.h Fri Jul 25 10:16:02 2025 -0400 @@ -3,10 +3,11 @@ #include "core/endian.h" +#include <cstdint> +#include <cstdlib> #include <string> +#include <type_traits> #include <vector> -#include <cstdint> -#include <type_traits> struct ByteStream { public: @@ -21,17 +22,19 @@ void SetEndianness(ByteOrder endian); template<typename T> - bool ReadBinary(T& ret) { + bool ReadBinary(T &ret) + { if (offset_ + sizeof(T) >= size_) return false; - ret = *reinterpret_cast<T*>(bytes_ + offset_); + std::memcpy(&ret, bytes_ + offset_, sizeof(ret)); Advance(sizeof(T)); return true; } template<typename T> - bool ReadInt(T& ret) { + bool ReadInt(T &ret) + { static_assert(std::is_integral<T>::value); if (!ReadBinary<T>(ret)) @@ -60,7 +63,7 @@ return true; } - bool ReadString(std::string& str, std::size_t size); + bool ReadString(std::string &str, std::size_t size); bool Advance(std::size_t amount); private: