Keyple C++  0.9.0
Keyple, an Open Source SDK for Ticketing
Static Public Member Functions | List of all members
keyple::core::util::ByteArrayUtil Class Reference

#include <ByteArrayUtil.h>

Static Public Member Functions

static std::vector< uint8_t > fromHex (const std::string &hex)
 
static std::string toHex (const std::vector< char > &byteArray)
 
static std::string toHex (const std::vector< uint8_t > &byteArray)
 
static int twoBytesToInt (const std::vector< uint8_t > &bytes, const int offset)
 
static int twoBytesSignedToInt (const std::vector< uint8_t > &bytes, const int offset)
 
static int threeBytesToInt (const std::vector< uint8_t > &bytes, const int offset)
 
static int threeBytesSignedToInt (const std::vector< uint8_t > &bytes, const int offset)
 
static int fourBytesToInt (const std::vector< uint8_t > &bytes, const int offset)
 

Detailed Description

Utils around byte arrays

Member Function Documentation

◆ fourBytesToInt()

int keyple::core::util::ByteArrayUtil::fourBytesToInt ( const std::vector< uint8_t > &  bytes,
const int  offset 
)
static

Convert four bytes from a byte array into an integer.

The four bytes are expected to be in the MSB first order (aka network order).

Throw an exception if the buffer is null or not long enough to contain 4 bytes.

Parameters
bytesbyte array
offsetoffset from which the 4 bytes are
Returns
the resulting int
Exceptions
IllegalArgumentExceptionif the buffer has a bad length

◆ fromHex()

std::vector< uint8_t > keyple::core::util::ByteArrayUtil::fromHex ( const std::string &  hex)
static

Create a byte array from an hexa string. This method allows spaces and "h".

Parameters
hexHexa string
Returns
byte array

◆ threeBytesSignedToInt()

int keyple::core::util::ByteArrayUtil::threeBytesSignedToInt ( const std::vector< uint8_t > &  bytes,
const int  offset 
)
static

Convert three bytes (signed) from a byte array into an integer.

The three bytes are expected to be in the MSB first order (aka network order).

The number is also considered as signed. That is, if the MSB (first left bit) is 1, then the number is negative and the conversion is done accordingly with the usual binary arithmetic.

Throw an exception if the buffer is null or not long enough to contain all 3 bytes.

Parameters
bytesbyte array containing a 3-byte signed number
offsetoffset from which the 3 bytes are
Returns
the resulting int
Exceptions
IllegalArgumentExceptionif the buffer has a bad length

◆ threeBytesToInt()

int keyple::core::util::ByteArrayUtil::threeBytesToInt ( const std::vector< uint8_t > &  bytes,
const int  offset 
)
static

Convert three bytes from a byte array into an integer.

The three bytes are expected to be in the MSB first order (aka network order).

Throw an exception if the buffer is null or not long enough to contain all 3 bytes.

Parameters
bytesbyte array
offsetoffset from which the 3 bytes are
Returns
the resulting int
Exceptions
IllegalArgumentExceptionif the buffer has a bad length

◆ toHex() [1/2]

std::string keyple::core::util::ByteArrayUtil::toHex ( const std::vector< char > &  byteArray)
static

Represents the byte array in a hexadecimal string.

Parameters
byteArraybyte array to represent to hex
Returns
Hex representation of the byte array

◆ toHex() [2/2]

std::string keyple::core::util::ByteArrayUtil::toHex ( const std::vector< uint8_t > &  byteArray)
static

Represents the byte array in a hexadecimal string.

Parameters
byteArraybyte array to represent to hex
Returns
Hex representation of the byte array

◆ twoBytesSignedToInt()

int keyple::core::util::ByteArrayUtil::twoBytesSignedToInt ( const std::vector< uint8_t > &  bytes,
const int  offset 
)
static

Convert two bytes (signed) from a byte array into an integer.

The two bytes are expected to be in the MSB first order (aka network order).

The number is also considered as signed. That is, if the MSB (first left bit) is 1, then the number is negative and the conversion is done accordingly with the usual binary arithmetic.

Throw an exception if the buffer is null or not long enough to contain 2 bytes.

Parameters
bytesbyte array
offsetoffset from which the 2 bytes are
Returns
the resulting int
Exceptions
IllegalArgumentExceptionif the buffer has a bad length

◆ twoBytesToInt()

int keyple::core::util::ByteArrayUtil::twoBytesToInt ( const std::vector< uint8_t > &  bytes,
const int  offset 
)
static

Convert two bytes (unsigned) from a byte array into an integer.

The two bytes are expected to be in the MSB first order (aka network order).

Throw an exception if the buffer is null or not long enough to contain 2 bytes.

Parameters
bytesbyte array
offsetoffset from which the 2 bytes are
Returns
the resulting int
Exceptions
IllegalArgumentExceptionif the buffer has a bad length

The documentation for this class was generated from the following files: