mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-07 12:01:50 +00:00
update byte_utils
This commit is contained in:
parent
3d3679c8b1
commit
0b3bb36188
5 changed files with 88 additions and 68 deletions
|
|
@ -18,7 +18,7 @@ namespace util {
|
|||
|
||||
Buffer(const T* src, size_t length)
|
||||
: ptr(std::make_unique<T[]>(length)), length(length) {
|
||||
std::memcpy(ptr, src, length);
|
||||
std::memcpy(ptr.get(), src, length);
|
||||
}
|
||||
|
||||
T& operator[](long long index) {
|
||||
|
|
|
|||
|
|
@ -41,6 +41,15 @@ namespace dataio {
|
|||
}
|
||||
}
|
||||
|
||||
/// @brief Convert hardware byte-order to big-endian
|
||||
/// @tparam T value type
|
||||
/// @param value source integer
|
||||
/// @return big-endian integer
|
||||
template <typename T>
|
||||
T h2be(T value){
|
||||
return be2h(value);
|
||||
}
|
||||
|
||||
/// @brief Convert little-endian to hardware byte-order
|
||||
/// @tparam T value type
|
||||
/// @param value source integer
|
||||
|
|
@ -54,6 +63,15 @@ namespace dataio {
|
|||
}
|
||||
}
|
||||
|
||||
/// @brief Convert hardware byte-order to little-endian
|
||||
/// @tparam T value type
|
||||
/// @param value source integer
|
||||
/// @return little-endian integer
|
||||
template <typename T>
|
||||
T h2le(T value){
|
||||
return le2h(value);
|
||||
}
|
||||
|
||||
/// @brief Read big-endian 16 bit signed integer from bytes
|
||||
inline int16_t read_int16_big(const ubyte* src, size_t offset) {
|
||||
return (src[offset] << 8) | (src[offset + 1]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue