Classes | Functions | Variables
gnsstk::BinUtils Namespace Reference

Detailed Description

Binary data utilities.

These functions and macros are to be used for manipulating binary data.

Note
the implementation of the byte swapping routines here has been chosen for both performance and correctness. The implementation of integer byte swapping, for example, cannot be used for floating point types.

Classes

class  CRCParam
 Encapsulate parameters for CRC computation. More...
 

Functions

void buhtoid (void *p, double v, unsigned pos=0)
 
void buhtoif (void *p, float v, unsigned pos=0)
 
void buhtoil (void *p, uint32_t v, unsigned pos=0)
 
void buhtoill (void *p, uint64_t v, unsigned pos=0)
 
void buhtois (void *p, uint16_t v, unsigned pos=0)
 
void buhtoisl (void *p, int32_t v, unsigned pos=0)
 
void buhtoisll (void *p, int64_t v, unsigned pos=0)
 
void buhtoiss (void *p, int16_t v, unsigned pos=0)
 
void buhtond (void *p, double v, unsigned pos=0)
 
void buhtonf (void *p, float v, unsigned pos=0)
 
void buhtonl (void *p, uint32_t v, unsigned pos=0)
 
void buhtonll (void *p, uint64_t v, unsigned pos=0)
 
void buhtons (void *p, uint16_t v, unsigned pos=0)
 
void buhtonsl (void *p, int32_t v, unsigned pos=0)
 
void buhtonsll (void *p, int64_t v, unsigned pos=0)
 
void buhtonss (void *p, int16_t v, unsigned pos=0)
 
void buitohd (const void *p, double &v, unsigned pos=0)
 
void buitohf (const void *p, float &v, unsigned pos=0)
 
void buitohl (const void *p, uint32_t &v, unsigned pos=0)
 
void buitohll (const void *p, uint64_t &v, unsigned pos=0)
 
void buitohs (const void *p, uint16_t &v, unsigned pos=0)
 
void buitohsl (const void *p, int32_t &v, unsigned pos=0)
 
void buitohsll (const void *p, int64_t &v, unsigned pos=0)
 
void buitohss (const void *p, int16_t &v, unsigned pos=0)
 
void buntohd (const void *p, double &v, unsigned pos=0)
 
void buntohf (const void *p, float &v, unsigned pos=0)
 
void buntohl (const void *p, uint32_t &v, unsigned pos=0)
 
void buntohll (const void *p, uint64_t &v, unsigned pos=0)
 
void buntohs (const void *p, uint16_t &v, unsigned pos=0)
 
void buntohsl (const void *p, int32_t &v, unsigned pos=0)
 
void buntohsll (const void *p, int64_t &v, unsigned pos=0)
 
void buntohss (const void *p, int16_t &v, unsigned pos=0)
 
uint32_t computeCRC (const unsigned char *data, unsigned long len, const CRCParam &params)
 
unsigned short countBits (uint32_t v)
 
template<class T >
decodeVar (const std::string &str, std::string::size_type pos)
 
template<class T >
decodeVar (std::string &str)
 
template<class T >
decodeVarLE (const std::string &str, std::string::size_type pos)
 
template<class T >
decodeVarLE (std::string &str)
 
template<class T >
std::string encodeVar (const T &v)
 
template<class T >
void encodeVar (const T &v, std::string &str, size_t pos=0)
 
template<class T >
std::string encodeVarLE (const T &v)
 
template<class T >
void encodeVarLE (const T &v, std::string &str, size_t pos=0)
 
 NEW_EXCEPTION_CLASS (CRCException, Exception)
 
unsigned long reflect (unsigned long crc, int bitnum)
 Reflects the lower bitnum bits of crc. More...
 
std::string xorChecksum (const std::string &str, unsigned wordSize)
 

Variables

const CRCParam CRC16 (16, 0x8005, 0, 0, true, true, true)
 CRC-16 parameters. More...
 
const CRCParam CRC24Q (24, 0x823ba9, 0, 0xffffff, true, false, false)
 CRC-24Q parameters. More...
 
const CRCParam CRC32 (32, 0x4c11db7, 0xffffffff, 0xffffffff, true, true, true)
 CRC-32 parameters. More...
 
const CRCParam CRCCCITT (16, 0x1021, 0xffff, 0, true, false, false)
 CCITT CRC parameters. More...
 
const CRCParam CRCGLOL3 (24, 0xc3267d, 0, 0xffffff, true, false, false)
 GLONASS CDMA L3 CRC parameters. More...
 

Function Documentation

◆ buhtoid()

void gnsstk::BinUtils::buhtoid ( void *  p,
double  v,
unsigned  pos = 0 
)
inline

Converts host byte order to Intel little-endian.

Parameters
[in,out]pa pointer to the buffer where the converted value will be stored.
[in]vthe value in host byte order.
[in]posan optional offset (bytes) into p to store the encoded value.

Definition at line 950 of file BinUtils.hpp.

◆ buhtoif()

void gnsstk::BinUtils::buhtoif ( void *  p,
float  v,
unsigned  pos = 0 
)
inline

Converts host byte order to Intel little-endian.

Parameters
[in,out]pa pointer to the buffer where the converted value will be stored.
[in]vthe value in host byte order.
[in]posan optional offset (bytes) into p to store the encoded value.

Definition at line 935 of file BinUtils.hpp.

◆ buhtoil()

void gnsstk::BinUtils::buhtoil ( void *  p,
uint32_t  v,
unsigned  pos = 0 
)
inline

Converts host byte order to Intel little-endian.

Parameters
[in,out]pa pointer to the buffer where the converted value will be stored.
[in]vthe value in host byte order.
[in]posan optional offset (bytes) into p to store the encoded value.

Definition at line 851 of file BinUtils.hpp.

◆ buhtoill()

void gnsstk::BinUtils::buhtoill ( void *  p,
uint64_t  v,
unsigned  pos = 0 
)
inline

Converts host byte order to Intel little-endian.

Parameters
[in,out]pa pointer to the buffer where the converted value will be stored.
[in]vthe value in host byte order.
[in]posan optional offset (bytes) into p to store the encoded value.

Definition at line 866 of file BinUtils.hpp.

◆ buhtois()

void gnsstk::BinUtils::buhtois ( void *  p,
uint16_t  v,
unsigned  pos = 0 
)
inline

Converts host byte order to Intel little-endian.

Parameters
[in,out]pa pointer to the buffer where the converted value will be stored.
[in]vthe value in host byte order.
[in]posan optional offset (bytes) into p to store the encoded value.

Definition at line 838 of file BinUtils.hpp.

◆ buhtoisl()

void gnsstk::BinUtils::buhtoisl ( void *  p,
int32_t  v,
unsigned  pos = 0 
)
inline

Converts host byte order to Intel little-endian.

Parameters
[in,out]pa pointer to the buffer where the converted value will be stored.
[in]vthe value in host byte order.
[in]posan optional offset (bytes) into p to store the encoded value.

Definition at line 899 of file BinUtils.hpp.

◆ buhtoisll()

void gnsstk::BinUtils::buhtoisll ( void *  p,
int64_t  v,
unsigned  pos = 0 
)
inline

Converts host byte order to Intel little-endian.

Parameters
[in,out]pa pointer to the buffer where the converted value will be stored.
[in]vthe value in host byte order.
[in]posan optional offset (bytes) into p to store the encoded value.

Definition at line 915 of file BinUtils.hpp.

◆ buhtoiss()

void gnsstk::BinUtils::buhtoiss ( void *  p,
int16_t  v,
unsigned  pos = 0 
)
inline

Converts host byte order to Intel little-endian.

Parameters
[in,out]pa pointer to the buffer where the converted value will be stored.
[in]vthe value in host byte order.
[in]posan optional offset (bytes) into p to store the encoded value.

Definition at line 885 of file BinUtils.hpp.

◆ buhtond()

void gnsstk::BinUtils::buhtond ( void *  p,
double  v,
unsigned  pos = 0 
)
inline

Converts host byte order to Network byte order (big-endian).

Parameters
[in,out]pa pointer to the buffer where the converted value will be stored.
[in]vthe value in host byte order.
[in]posan optional offset (bytes) into p to store the encoded value.

Definition at line 1082 of file BinUtils.hpp.

◆ buhtonf()

void gnsstk::BinUtils::buhtonf ( void *  p,
float  v,
unsigned  pos = 0 
)
inline

Converts host byte order to Network byte order (big-endian).

Parameters
[in,out]pa pointer to the buffer where the converted value will be stored.
[in]vthe value in host byte order.
[in]posan optional offset (bytes) into p to store the encoded value.

Definition at line 1067 of file BinUtils.hpp.

◆ buhtonl()

void gnsstk::BinUtils::buhtonl ( void *  p,
uint32_t  v,
unsigned  pos = 0 
)
inline

Converts host byte order to Network byte order (big-endian).

Parameters
[in,out]pa pointer to the buffer where the converted value will be stored.
[in]vthe value in host byte order.
[in]posan optional offset (bytes) into p to store the encoded value.

Definition at line 983 of file BinUtils.hpp.

◆ buhtonll()

void gnsstk::BinUtils::buhtonll ( void *  p,
uint64_t  v,
unsigned  pos = 0 
)
inline

Converts host byte order to Network byte order (big-endian).

Parameters
[in,out]pa pointer to the buffer where the converted value will be stored.
[in]vthe value in host byte order.
[in]posan optional offset (bytes) into p to store the encoded value.

Definition at line 998 of file BinUtils.hpp.

◆ buhtons()

void gnsstk::BinUtils::buhtons ( void *  p,
uint16_t  v,
unsigned  pos = 0 
)
inline

Converts host byte order to Network byte order (big-endian).

Parameters
[in,out]pa pointer to the buffer where the converted value will be stored.
[in]vthe value in host byte order.
[in]posan optional offset (bytes) into p to store the encoded value.

Definition at line 970 of file BinUtils.hpp.

◆ buhtonsl()

void gnsstk::BinUtils::buhtonsl ( void *  p,
int32_t  v,
unsigned  pos = 0 
)
inline

Converts host byte order to Network byte order (big-endian).

Parameters
[in,out]pa pointer to the buffer where the converted value will be stored.
[in]vthe value in host byte order.
[in]posan optional offset (bytes) into p to store the encoded value.

Definition at line 1031 of file BinUtils.hpp.

◆ buhtonsll()

void gnsstk::BinUtils::buhtonsll ( void *  p,
int64_t  v,
unsigned  pos = 0 
)
inline

Converts host byte order to Network byte order (big-endian).

Parameters
[in,out]pa pointer to the buffer where the converted value will be stored.
[in]vthe value in host byte order.
[in]posan optional offset (bytes) into p to store the encoded value.

Definition at line 1047 of file BinUtils.hpp.

◆ buhtonss()

void gnsstk::BinUtils::buhtonss ( void *  p,
int16_t  v,
unsigned  pos = 0 
)
inline

Converts host byte order to Network byte order (big-endian).

Parameters
[in,out]pa pointer to the buffer where the converted value will be stored.
[in]vthe value in host byte order.
[in]posan optional offset (bytes) into p to store the encoded value.

Definition at line 1017 of file BinUtils.hpp.

◆ buitohd()

void gnsstk::BinUtils::buitohd ( const void *  p,
double &  v,
unsigned  pos = 0 
)
inline

Converts Intel little-endian to host byte order.

Parameters
[in]pa pointer to the buffer containing the little-endian value.
[out]vthe value in host byte order.
[in]posan optional offset (bytes) into p to decode from.

Definition at line 686 of file BinUtils.hpp.

◆ buitohf()

void gnsstk::BinUtils::buitohf ( const void *  p,
float &  v,
unsigned  pos = 0 
)
inline

Converts Intel little-endian to host byte order.

Parameters
[in]pa pointer to the buffer containing the little-endian value.
[out]vthe value in host byte order.
[in]posan optional offset (bytes) into p to decode from.

Definition at line 671 of file BinUtils.hpp.

◆ buitohl()

void gnsstk::BinUtils::buitohl ( const void *  p,
uint32_t &  v,
unsigned  pos = 0 
)
inline

Converts Intel little-endian to host byte order.

Parameters
[in]pa pointer to the buffer containing the little-endian value.
[out]vthe value in host byte order.
[in]posan optional offset (bytes) into p to decode from.

Definition at line 587 of file BinUtils.hpp.

◆ buitohll()

void gnsstk::BinUtils::buitohll ( const void *  p,
uint64_t &  v,
unsigned  pos = 0 
)
inline

Converts Intel little-endian to host byte order.

Parameters
[in]pa pointer to the buffer containing the little-endian value.
[out]vthe value in host byte order.
[in]posan optional offset (bytes) into p to decode from.

Definition at line 602 of file BinUtils.hpp.

◆ buitohsl()

void gnsstk::BinUtils::buitohsl ( const void *  p,
int32_t &  v,
unsigned  pos = 0 
)
inline

Converts Intel little-endian to host byte order.

Parameters
[in]pa pointer to the buffer containing the little-endian value.
[out]vthe value in host byte order.
[in]posan optional offset (bytes) into p to decode from.

Definition at line 635 of file BinUtils.hpp.

◆ buitohsll()

void gnsstk::BinUtils::buitohsll ( const void *  p,
int64_t &  v,
unsigned  pos = 0 
)
inline

Converts Intel little-endian to host byte order.

Parameters
[in]pa pointer to the buffer containing the little-endian value.
[out]vthe value in host byte order.
[in]posan optional offset (bytes) into p to decode from.

Definition at line 651 of file BinUtils.hpp.

◆ buitohss()

void gnsstk::BinUtils::buitohss ( const void *  p,
int16_t &  v,
unsigned  pos = 0 
)
inline

Converts Intel little-endian to host byte order.

Parameters
[in]pa pointer to the buffer containing the little-endian value.
[out]vthe value in host byte order.
[in]posan optional offset (bytes) into p to decode from.

Definition at line 621 of file BinUtils.hpp.

◆ buntohd()

void gnsstk::BinUtils::buntohd ( const void *  p,
double &  v,
unsigned  pos = 0 
)
inline

Converts Network (big-endian) to host byte order.

Parameters
[in]pa pointer to the buffer containing the big-endian value.
[out]vthe value in host byte order.
[in]posan optional offset (bytes) into p to decode from.

Definition at line 818 of file BinUtils.hpp.

◆ buntohf()

void gnsstk::BinUtils::buntohf ( const void *  p,
float &  v,
unsigned  pos = 0 
)
inline

Converts Network (big-endian) to host byte order.

Parameters
[in]pa pointer to the buffer containing the big-endian value.
[out]vthe value in host byte order.
[in]posan optional offset (bytes) into p to decode from.

Definition at line 803 of file BinUtils.hpp.

◆ buntohl()

void gnsstk::BinUtils::buntohl ( const void *  p,
uint32_t &  v,
unsigned  pos = 0 
)
inline

Converts Network (big-endian) to host byte order.

Parameters
[in]pa pointer to the buffer containing the big-endian value.
[out]vthe value in host byte order.
[in]posan optional offset (bytes) into p to decode from.

Definition at line 719 of file BinUtils.hpp.

◆ buntohll()

void gnsstk::BinUtils::buntohll ( const void *  p,
uint64_t &  v,
unsigned  pos = 0 
)
inline

Converts Network (big-endian) to host byte order.

Parameters
[in]pa pointer to the buffer containing the big-endian value.
[out]vthe value in host byte order.
[in]posan optional offset (bytes) into p to decode from.

Definition at line 734 of file BinUtils.hpp.

◆ buntohs()

void gnsstk::BinUtils::buntohs ( const void *  p,
uint16_t &  v,
unsigned  pos = 0 
)
inline

Converts Network (big-endian) to host byte order.

Parameters
[in]pa pointer to the buffer containing the big-endian value.
[out]vthe value in host byte order.
[in]posan optional offset (bytes) into p to decode from.

Definition at line 706 of file BinUtils.hpp.

◆ buntohsl()

void gnsstk::BinUtils::buntohsl ( const void *  p,
int32_t &  v,
unsigned  pos = 0 
)
inline

Converts Network (big-endian) to host byte order.

Parameters
[in]pa pointer to the buffer containing the big-endian value.
[out]vthe value in host byte order.
[in]posan optional offset (bytes) into p to decode from.

Definition at line 767 of file BinUtils.hpp.

◆ buntohsll()

void gnsstk::BinUtils::buntohsll ( const void *  p,
int64_t &  v,
unsigned  pos = 0 
)
inline

Converts Network (big-endian) to host byte order.

Parameters
[in]pa pointer to the buffer containing the big-endian value.
[out]vthe value in host byte order.
[in]posan optional offset (bytes) into p to decode from.

Definition at line 783 of file BinUtils.hpp.

◆ buntohss()

void gnsstk::BinUtils::buntohss ( const void *  p,
int16_t &  v,
unsigned  pos = 0 
)
inline

Converts Network (big-endian) to host byte order.

Parameters
[in]pa pointer to the buffer containing the big-endian value.
[out]vthe value in host byte order.
[in]posan optional offset (bytes) into p to decode from.

Definition at line 753 of file BinUtils.hpp.

◆ computeCRC()

uint32_t gnsstk::BinUtils::computeCRC ( const unsigned char *  data,
unsigned long  len,
const CRCParam params 
)
inline

Compute CRC (suitable for polynomial orders from 1 to 32). Does bit-by-bit computation (brute-force, no look-up tables).

Parameters
[in]datadata to process CRC on.
[in]lenlength of data to process (in bytes).
[in]paramssee documentation of CRCParam:w
Returns
the CRC value

Definition at line 477 of file BinUtils.hpp.

◆ countBits()

unsigned short gnsstk::BinUtils::countBits ( uint32_t  v)
inline

Count the set bits in an 32-bit unsigned integer. Originated due to need in EngNav::checkParity

Definition at line 342 of file BinUtils.hpp.

◆ decodeVar() [1/2]

template<class T >
T gnsstk::BinUtils::decodeVar ( const std::string &  str,
std::string::size_type  pos 
)
inline

Decode the item specified from the string and convert it from network byte order to host byte order.

Parameters
[in]strthe string from which to obtain data.
[in]posoffset into the string from which to pull the data.
Warning
This function does not check for appropriate string length.

Definition at line 366 of file BinUtils.hpp.

◆ decodeVar() [2/2]

template<class T >
T gnsstk::BinUtils::decodeVar ( std::string &  str)
inline

Decode and remove the item specified from the head of the string and convert it from network byte order to host byte order.

Parameters
[in,out]strthe string from which to obtain data.
Warning
This function does not check for appropriate string length.

Definition at line 398 of file BinUtils.hpp.

◆ decodeVarLE() [1/2]

template<class T >
T gnsstk::BinUtils::decodeVarLE ( const std::string &  str,
std::string::size_type  pos 
)
inline

Decode the item specified from the string and convert it from little-endian byte order to host byte order.

Parameters
[in]strthe string from which to obtain data.
[in]posoffset into the string from which to pull the data.
Warning
This function does not check for appropriate string length.

Definition at line 383 of file BinUtils.hpp.

◆ decodeVarLE() [2/2]

template<class T >
T gnsstk::BinUtils::decodeVarLE ( std::string &  str)
inline

Decode and remove the item specified from the head of the string and convert it from little-endian byte order to host byte order.

Parameters
[in,out]strthe string from which to obtain data.
Warning
This function does not check for appropriate string length.

Definition at line 406 of file BinUtils.hpp.

◆ encodeVar() [1/2]

template<class T >
std::string gnsstk::BinUtils::encodeVar ( const T &  v)
inline

Add the network ordered binary representation of a var to the the given string.

Parameters
[in]vthe object of type T to convert to a string.

Definition at line 414 of file BinUtils.hpp.

◆ encodeVar() [2/2]

template<class T >
void gnsstk::BinUtils::encodeVar ( const T &  v,
std::string &  str,
size_t  pos = 0 
)
inline

Add the network ordered binary representation of a var to the the given string.

Parameters
[in]vthe object of type T to convert to a string.
[in,out]strthe string where the encoded data will be stored.
[in]posthe position in str where the encoded variable will be stored.

Definition at line 425 of file BinUtils.hpp.

◆ encodeVarLE() [1/2]

template<class T >
std::string gnsstk::BinUtils::encodeVarLE ( const T &  v)
inline

Add the little-endian binary representation of a var to the the given string.

Parameters
[in]vthe object of type T to convert to a string.

Definition at line 436 of file BinUtils.hpp.

◆ encodeVarLE() [2/2]

template<class T >
void gnsstk::BinUtils::encodeVarLE ( const T &  v,
std::string &  str,
size_t  pos = 0 
)
inline

Add the little-endian binary representation of a var to the the given string.

Parameters
[in]vthe object of type T to convert to a string.
[in,out]strthe string where the encoded data will be stored.
[in]posthe position in str where the encoded variable will be stored.

Definition at line 447 of file BinUtils.hpp.

◆ reflect()

unsigned long gnsstk::BinUtils::reflect ( unsigned long  crc,
int  bitnum 
)
inline

Reflects the lower bitnum bits of crc.

Definition at line 457 of file BinUtils.hpp.

◆ xorChecksum()

std::string gnsstk::BinUtils::xorChecksum ( const std::string &  str,
unsigned  wordSize 
)
inline

Calculate an Exclusive-OR Checksum on the string str.

Parameters
[in]strThe encoded data for which the checksum is to be computed. The size of this string must be evenly divisible by wordSize.
[in]wordSizeThe size of the checksum in bytes.
Returns
the calculated checksum in the same byte order as str.
Exceptions
gnsstk::InvalidParameterif there is a partial word at the end of str.

Definition at line 551 of file BinUtils.hpp.

Variable Documentation

◆ CRC16

const GNSSTK_EXPORT CRCParam gnsstk::BinUtils::CRC16

CRC-16 parameters.

Definition at line 307 of file BinUtils.hpp.

◆ CRC24Q

const GNSSTK_EXPORT CRCParam gnsstk::BinUtils::CRC24Q

CRC-24Q parameters.

Definition at line 311 of file BinUtils.hpp.

◆ CRC32

const GNSSTK_EXPORT CRCParam gnsstk::BinUtils::CRC32

CRC-32 parameters.

Definition at line 309 of file BinUtils.hpp.

◆ CRCCCITT

const GNSSTK_EXPORT CRCParam gnsstk::BinUtils::CRCCCITT

CCITT CRC parameters.

Definition at line 305 of file BinUtils.hpp.

◆ CRCGLOL3

const GNSSTK_EXPORT CRCParam gnsstk::BinUtils::CRCGLOL3

GLONASS CDMA L3 CRC parameters.

Definition at line 313 of file BinUtils.hpp.



gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:46