VSM C++ SDK
Vehicle Specific Modules SDK
endian.h File Reference

VSM definitions to work with byte order. More...

#include <ugcs/vsm/defs.h>
#include <stdint.h>

Go to the source code of this file.

Classes

class  ugcs::vsm::Bo_value< T, Converter >
 Helper class for byte-order-dependent value representation. More...
 

Namespaces

 ugcs
 UGCS root namespace.
 
 ugcs::vsm
 All VSM SDK functionality resides in this namespace.
 

Macros

#define VSM_BSWAP16(x)   (((x) >> 8) | ((x) << 8))
 Swap bytes in 16-bits integer value. More...
 
#define VSM_BSWAP32(x)   __builtin_bswap32(x)
 Swap bytes in 32-bits integer value. More...
 
#define VSM_BSWAP64(x)   __builtin_bswap64(x)
 Swap bytes in 64-bits integer value. More...
 
#define __VSM_BO_INT(type_size)   int ## type_size ## _t
 Definitions for byte order conversions for all integer types. More...
 
#define __VSM_BO_UINT(type_size)   uint ## type_size ## _t
 
#define _VSM_DEF_BO_CONV(type_size, type_name)
 
#define VSM_DEF_BO_CONV(type_size)
 

Typedefs

template<typename T >
using ugcs::vsm::Le_value = Bo_value< T, internal::Le_converter >
 Little-endian value wrapper. More...
 
template<typename T >
using ugcs::vsm::Be_value = Bo_value< T, internal::Be_converter >
 Big-endian value wrapper. More...
 
typedef Le_value< int8_t > ugcs::vsm::Le_int8
 Standard primitive types for little-endian byte order. More...
 
typedef Le_value< uint8_t > ugcs::vsm::Le_uint8
 
typedef Le_value< int16_t > ugcs::vsm::Le_int16
 
typedef Le_value< uint16_t > ugcs::vsm::Le_uint16
 
typedef Le_value< int32_t > ugcs::vsm::Le_int32
 
typedef Le_value< uint32_t > ugcs::vsm::Le_uint32
 
typedef Le_value< float > ugcs::vsm::Le_float
 
typedef Le_value< double > ugcs::vsm::Le_double
 
typedef Be_value< int8_t > ugcs::vsm::Be_int8
 Standard primitive types for big-endian byte order. More...
 
typedef Be_value< uint8_t > ugcs::vsm::Be_uint8
 
typedef Be_value< int16_t > ugcs::vsm::Be_int16
 
typedef Be_value< uint16_t > ugcs::vsm::Be_uint16
 
typedef Be_value< int32_t > ugcs::vsm::Be_int32
 
typedef Be_value< uint32_t > ugcs::vsm::Be_uint32
 
typedef Be_value< float > ugcs::vsm::Be_float
 
typedef Be_value< double > ugcs::vsm::Be_double
 

Functions

constexpr bool ugcs::vsm::Is_system_le ()
 Check if the system is little-endian. More...
 
constexpr bool ugcs::vsm::Is_system_be ()
 Check if the system is big-endian. More...
 
template<typename T >
constexpr T ugcs::vsm::Convert_be_8 (T x)
 Stub for easier conversion functions generalization. More...
 
template<typename T >
constexpr T ugcs::vsm::Convert_be_16 (T x)
 Convert 16 bits value byte order from BE to host byte order and vice versa. More...
 
template<typename T >
constexpr T ugcs::vsm::Convert_be_32 (T x)
 Convert 32 bits value byte order from BE to host byte order and vice versa. More...
 
template<typename T >
constexpr T ugcs::vsm::Convert_be_64 (T x)
 Convert 64 bits value byte order from BE to host byte order and vice versa. More...
 
template<typename T >
constexpr T ugcs::vsm::Convert_le_8 (T x)
 Stub for easier conversion functions generalization. More...
 
template<typename T >
constexpr T ugcs::vsm::Convert_le_16 (T x)
 Convert 16 bits value byte order from LE to host byte order and vice versa. More...
 
template<typename T >
constexpr T ugcs::vsm::Convert_le_32 (T x)
 Convert 32 bits value byte order from LE to host byte order and vice versa. More...
 
template<typename T >
constexpr T ugcs::vsm::Convert_le_64 (T x)
 Convert 64 bits value byte order from LE to host byte order and vice versa. More...
 
template<typename T >
constexpr T ugcs::vsm::Convert_nh_8 (T x)
 Stub for easier conversion functions generalization. More...
 
template<typename T >
constexpr T ugcs::vsm::Convert_nh_16 (T x)
 Convert 16 bits value byte order from network to host byte order and vice versa. More...
 
template<typename T >
constexpr T ugcs::vsm::Convert_nh_32 (T x)
 Convert 32 bits value byte order from network to host byte order and vice versa. More...
 
template<typename T >
constexpr T ugcs::vsm::Convert_nh_64 (T x)
 Convert 64 bits value byte order from network to host byte order and vice versa. More...
 
constexpr int8_t ugcs::vsm::Ntoh (int8_t x)
 Convert value from network to host byte order. More...
 
constexpr int8_t ugcs::vsm::Hton (int8_t x)
 Convert value from host to network byte order. More...
 
constexpr int8_t ugcs::vsm::Le (int8_t x)
 Convert value from LE to host byte order and vice versa. More...
 
constexpr int8_t ugcs::vsm::Be (int8_t x)
 Convert value from BE to host byte order and vice versa. More...
 
constexpr uint8_t ugcs::vsm::Ntoh (uint8_t x)
 Convert value from network to host byte order. More...
 
constexpr uint8_t ugcs::vsm::Hton (uint8_t x)
 Convert value from host to network byte order. More...
 
constexpr uint8_t ugcs::vsm::Le (uint8_t x)
 Convert value from LE to host byte order and vice versa. More...
 
constexpr uint8_t ugcs::vsm::Be (uint8_t x)
 Convert value from BE to host byte order and vice versa. More...
 
constexpr int16_t ugcs::vsm::Ntoh (int16_t x)
 Convert value from network to host byte order. More...
 
constexpr int16_t ugcs::vsm::Hton (int16_t x)
 Convert value from host to network byte order. More...
 
constexpr int16_t ugcs::vsm::Le (int16_t x)
 Convert value from LE to host byte order and vice versa. More...
 
constexpr int16_t ugcs::vsm::Be (int16_t x)
 Convert value from BE to host byte order and vice versa. More...
 
constexpr uint16_t ugcs::vsm::Ntoh (uint16_t x)
 Convert value from network to host byte order. More...
 
constexpr uint16_t ugcs::vsm::Hton (uint16_t x)
 Convert value from host to network byte order. More...
 
constexpr uint16_t ugcs::vsm::Le (uint16_t x)
 Convert value from LE to host byte order and vice versa. More...
 
constexpr uint16_t ugcs::vsm::Be (uint16_t x)
 Convert value from BE to host byte order and vice versa. More...
 
constexpr int32_t ugcs::vsm::Ntoh (int32_t x)
 Convert value from network to host byte order. More...
 
constexpr int32_t ugcs::vsm::Hton (int32_t x)
 Convert value from host to network byte order. More...
 
constexpr int32_t ugcs::vsm::Le (int32_t x)
 Convert value from LE to host byte order and vice versa. More...
 
constexpr int32_t ugcs::vsm::Be (int32_t x)
 Convert value from BE to host byte order and vice versa. More...
 
constexpr uint32_t ugcs::vsm::Ntoh (uint32_t x)
 Convert value from network to host byte order. More...
 
constexpr uint32_t ugcs::vsm::Hton (uint32_t x)
 Convert value from host to network byte order. More...
 
constexpr uint32_t ugcs::vsm::Le (uint32_t x)
 Convert value from LE to host byte order and vice versa. More...
 
constexpr uint32_t ugcs::vsm::Be (uint32_t x)
 Convert value from BE to host byte order and vice versa. More...
 
constexpr int64_t ugcs::vsm::Ntoh (int64_t x)
 Convert value from network to host byte order. More...
 
constexpr int64_t ugcs::vsm::Hton (int64_t x)
 Convert value from host to network byte order. More...
 
constexpr int64_t ugcs::vsm::Le (int64_t x)
 Convert value from LE to host byte order and vice versa. More...
 
constexpr int64_t ugcs::vsm::Be (int64_t x)
 Convert value from BE to host byte order and vice versa. More...
 
constexpr uint64_t ugcs::vsm::Ntoh (uint64_t x)
 Convert value from network to host byte order. More...
 
constexpr uint64_t ugcs::vsm::Hton (uint64_t x)
 Convert value from host to network byte order. More...
 
constexpr uint64_t ugcs::vsm::Le (uint64_t x)
 Convert value from LE to host byte order and vice versa. More...
 
constexpr uint64_t ugcs::vsm::Be (uint64_t x)
 Convert value from BE to host byte order and vice versa. More...
 
constexpr float ugcs::vsm::Hton (float x)
 Convert float type from host to network format. More...
 
constexpr float ugcs::vsm::Ntoh (float x)
 Convert float type from network to host format. More...
 
constexpr double ugcs::vsm::Hton (double x)
 Convert double type from host to network format. More...
 
constexpr double ugcs::vsm::Ntoh (double x)
 Convert double type from network to host format. More...
 
constexpr float ugcs::vsm::Le (float x)
 Convert float type from LE to host format. More...
 
constexpr float ugcs::vsm::Be (float x)
 Convert float type from BE to host format. More...
 
constexpr double ugcs::vsm::Le (double x)
 Convert float type from LE to host format. More...
 
constexpr double ugcs::vsm::Be (double x)
 Convert float type from BE to host format. More...
 
 Bo_value (T value=0)
 Construct value. More...
 
Bo_valueoperator= (T value)
 Assign new value. More...
 
 operator T () const
 Cast to underlying type. More...
 
Get () const
 Get the value of underlying type. More...
 

Detailed Description

VSM definitions to work with byte order.

There is "endian.h" file present on some systems but it is not standardized and thus not cross-platform.

Macro Definition Documentation

#define __VSM_BO_INT (   type_size)    int ## type_size ## _t

Definitions for byte order conversions for all integer types.

#define _VSM_DEF_BO_CONV (   type_size,
  type_name 
)
Value:
\
constexpr type_name \
Ntoh(type_name x) \
{ \
return Convert_nh_ ## type_size (x); \
} \
\ \
constexpr type_name \
Hton(type_name x) \
{ \
return Convert_nh_ ## type_size (x); \
} \
\ \
constexpr type_name \
Le(type_name x) \
{ \
return Convert_le_ ## type_size (x); \
} \
\ \
constexpr type_name \
Be(type_name x) \
{ \
return Convert_be_ ## type_size (x); \
} \
constexpr double Be(double x)
Convert float type from BE to host format.
Definition: endian.h:289
constexpr double Le(double x)
Convert float type from LE to host format.
Definition: endian.h:281
constexpr double Hton(double x)
Convert double type from host to network format.
Definition: endian.h:249
constexpr double Ntoh(double x)
Convert double type from network to host format.
Definition: endian.h:257
#define VSM_BSWAP16 (   x)    (((x) >> 8) | ((x) << 8))

Swap bytes in 16-bits integer value.

#define VSM_BSWAP32 (   x)    __builtin_bswap32(x)

Swap bytes in 32-bits integer value.

#define VSM_BSWAP64 (   x)    __builtin_bswap64(x)

Swap bytes in 64-bits integer value.

#define VSM_DEF_BO_CONV (   type_size)
Value:
_VSM_DEF_BO_CONV(type_size, __VSM_BO_INT(type_size)) \
_VSM_DEF_BO_CONV(type_size, __VSM_BO_UINT(type_size))
#define __VSM_BO_INT(type_size)
Definitions for byte order conversions for all integer types.
Definition: endian.h:188

Function Documentation

__attribute__::Bo_value ( value = 0)

Construct value.

Parameters
valueValue in host byte order.
T __attribute__::Get ( ) const

Get the value of underlying type.

Returns
Value in host byte order.
__attribute__::operator T ( ) const

Cast to underlying type.

Returns
Value in host byte order.
Bo_value& __attribute__::operator= ( value)

Assign new value.

Parameters
valueValue in host byte order.