R-Type 0.1
Loading...
Searching...
No Matches
rtype::protocol::BigEndian< T > Struct Template Reference

Unsigned integer stored as big-endian bytes, with an alignment of 1. More...

#include <Protocol/BigEndian.hpp>

Public Member Functions

constexpr BigEndian ()=default
 Creates a zero value.
 
constexpr BigEndian (T value)
 Stores a host value in big-endian order.
 
constexpr T get () const
 Returns the value in host byte order.
 
constexpr operator T () const
 Converts to the value in host byte order.
 

Public Attributes

std::array< std::uint8_t, sizeof(T)> bytes {}
 Value in big-endian order.
 

Detailed Description

template<std::unsigned_integral T>
struct rtype::protocol::BigEndian< T >

Unsigned integer stored as big-endian bytes, with an alignment of 1.

Structs made only of these fields never contain padding, so they can be copied byte for byte to and from the wire on any host.

Template Parameters
TUnsigned integer type that is stored.

Constructor & Destructor Documentation

◆ BigEndian()

template<std::unsigned_integral T>
rtype::protocol::BigEndian< T >::BigEndian ( T value)
inlineconstexpr

Stores a host value in big-endian order.

Parameters
valueValue in host byte order.

Member Function Documentation

◆ get()

template<std::unsigned_integral T>
T rtype::protocol::BigEndian< T >::get ( ) const
inlineconstexpr

Returns the value in host byte order.

Returns
The decoded value.