Class endian_codec
Synopsis
#include "breeze/endianness/endian_codec.hpp"
template<
typename EndianPolicy,
typename T,
typename Byte
>
class endian_codec
Description
Converter from/to byte sequence representations.
Converts generic values to/from (byte-)sequence representations.
In general, endian_codec
can read and store a representation of a value as a sequence of smaller units, regardless of their widths. It is mostly useful to read and write values independently of the endianness they are stored in, as long as the endianness type is known.
- Type requirements
T
andByte
shall be integral types with no sign. The width ofT
must be smaller than the width ofByte
(e.g. you can store a 32-bit integer into a 64-bit one) or an exact multiple of it.- Warning
- Given its generality it might be a good idea to rename this to something like "order_codec" or similar; feedback is welcome.
- Todo
- Check this; is it true for user-policies?
Methods
decode | Returns: The value of type T encoded, according to EndianPolicy , in a range that begins with source . | |
encode | Writes (encodes) the value value into a range starting with dest , according to EndianPolicy . |
Source
Lines 204-247 in breeze/endianness/endian_codec.hpp.
template<
typename EndianPolicy,
typename T,
typename Byte
>
class endian_codec
{
private:
static std::ptrdiff_t const
n = endian_codec_private::
required_count< T, Byte >::value ;
public:
static std::ptrdiff_t const
required_count = n ; // gps experimental
//! Writes (encodes) the value \c value into a range starting
//! with \c dest, according to \c EndianPolicy.
// -----------------------------------------------------------------------
template< typename OutputIter >
static void encode( T const & value, OutputIter dest )
{
endian_codec_private::endian_codec< EndianPolicy,
T,
Byte,
n >::encode( value, dest ) ;
}
//! \return
//! The value of type \c T encoded, according to \c
//! EndianPolicy, in a range that begins with \c source.
//!
//! \note
//! The \c value_type of \c InputIter can be larger than \c
//! Byte.
// -----------------------------------------------------------------------
template< typename InputIter >
static T decode( InputIter source )
{
return endian_codec_private::endian_codec< EndianPolicy,
T,
Byte,
n >::decode( source ) ;
}
} ;