crawlserv++  [under development]
Application for crawling and analyzing textual content of websites.
crawlservpp::Helper::Bytes Namespace Reference

Namespace for global byte operation helper functions. More...

Typedefs

using Bytes = std::vector< std::uint8_t >
 

Constants

constexpr auto first {0}
 Index of the first byte. More...
 
constexpr auto second {1}
 Index of the second byte. More...
 
constexpr auto third {2}
 Index of the third byte. More...
 
constexpr auto fourth {3}
 Index of the fourth byte. More...
 
constexpr auto fifth {4}
 Index of the fifth byte. More...
 
constexpr auto sixth {5}
 Index of the sixth byte. More...
 
constexpr auto seventh {6}
 Index of the seventh byte. More...
 
constexpr auto eighth {7}
 Index of the eighth byte. More...
 
constexpr auto oneByteBits {8}
 One byte in bits. More...
 
constexpr auto twoBytesBits {16}
 Two bytes in bits. More...
 
constexpr auto threeBytesBits {24}
 Three bytes in bits. More...
 
constexpr auto fourBytesBits {32}
 Four bytes in bits. More...
 
constexpr auto fiveBytesBits {40}
 Five bytes in bits. More...
 
constexpr auto sixBytesBits {48}
 Six bytes in bits. More...
 
constexpr auto sevenBytesBits {56}
 Seven bytes in bits. More...
 
constexpr auto sizeEight {8}
 Size of eight bytes. More...
 
constexpr auto sizeFour {4}
 Size of four bytes. More...
 
constexpr auto sizeTwo {2}
 Size of two bytes. More...
 

Endianness

bool isBigEndian () noexcept
 Returns whether the machine running this code uses big endianness. More...
 
bool isFloatBigEndian () noexcept
 Returns whether the machine running this code uses big endianness for floating-point numbers. More...
 

Bytes-to-Number Conversion

std::uint64_t bytesToUInt64 (const Bytes &bytes, std::size_t &pos)
 Retrieve an unsigned 64-bit number from a vector of bytes. More...
 
std::uint64_t bytesToUInt64 (const Bytes &bytes, std::size_t &pos, std::size_t len)
 Retrieve an unsigned 64-bit number from a vector of bytes. More...
 
std::int64_t bytesToInt64 (const Bytes &bytes, std::size_t &pos)
 Retrieve a signed 64-bit number from a vector of bytes. More...
 
std::int64_t bytesToInt64 (const Bytes &bytes, std::size_t &pos, std::size_t len)
 Retrieve a signed 64-bit number from a vector of bytes. More...
 
std::uint32_t bytesToUInt32 (const Bytes &bytes, std::size_t &pos)
 Retrieve an unsigned 32-bit number from a vector of bytes. More...
 
std::int32_t bytesToInt32 (const Bytes &bytes, std::size_t &pos)
 Retrieve a signed 32-bit number from a vector of bytes. More...
 
std::uint16_t bytesToUInt16 (const Bytes &bytes, std::size_t &pos)
 Retrieve an unsigned 16-bit number from a vector of bytes. More...
 
std::int16_t bytesToInt16 (const Bytes &bytes, std::size_t &pos)
 Retrieve a signed 16-bit number from a vector of bytes. More...
 
double bytesToDouble (const Bytes &bytes, std::size_t &pos)
 Retrieves a IEEE 754 double-precision binary floating-point number from a vector of bytes. More...
 

Number-to-Bytes Conversion

std::array< std::uint8_t, sizeEightuInt64ToBytes (std::uint64_t number)
 Converts an unsigned 64-bit number to an array of eight bytes. More...
 
std::array< std::uint8_t, sizeEightint64ToBytes (std::int64_t number)
 Converts a signed 64-bit number to an array of eight bytes. More...
 
std::array< std::uint8_t, sizeFouruInt32ToBytes (std::uint32_t number)
 Converts an unsigned 32-bit number to an array of four bytes. More...
 
std::array< std::uint8_t, sizeFourint32ToBytes (std::int32_t number)
 Converts an signed 32-bit number to an array of four bytes. More...
 
std::array< std::uint8_t, sizeTwouInt16ToBytes (std::uint16_t number)
 Converts an unsigned 16-bit number to an array of two bytes. More...
 
std::array< std::uint8_t, sizeTwoint16ToBytes (std::int16_t number)
 Converts an signed 16-bit number to an array of two bytes. More...
 
std::array< std::uint8_t, sizeEightdoubleToBytes (double number)
 Converts a floating-point number with double precision to an array of four bytes. More...
 

String Representation

std::string byteToHexString (std::uint8_t byte)
 Converts a byte to a string containing the byte in hexadecimal format. More...
 
std::string charToString (char c)
 Converts a character to a string. More...
 

Detailed Description

Namespace for global byte operation helper functions.

Typedef Documentation

◆ Bytes

using crawlservpp::Helper::Bytes::Bytes = typedef std::vector<std::uint8_t>

Function Documentation

◆ bytesToDouble()

double crawlservpp::Helper::Bytes::bytesToDouble ( const Bytes bytes,
std::size_t &  pos 
)
inline

Retrieves a IEEE 754 double-precision binary floating-point number from a vector of bytes.

Parameters
bytesConstant reference to a vector containing the bytes.
posReference to the start position of the floating-point number contained in the bytes. The position will be updated after reading the floating-point number from the bytes.
Returns
The floating-point number as read from the bytes.

References eighth, fifth, first, fourth, isFloatBigEndian(), crawlservpp::Helper::Queue::reverse(), second, seventh, sixth, sizeEight, and third.

Referenced by crawlservpp::Data::PickleDict::writeTo().

◆ bytesToInt16()

std::int16_t crawlservpp::Helper::Bytes::bytesToInt16 ( const Bytes bytes,
std::size_t &  pos 
)
inline

Retrieve a signed 16-bit number from a vector of bytes.

Parameters
bytesConstant reference to a vector containing the bytes.
posReference to the start position of the number contained in the bytes. The position will be updated after reading the number from the bytes.
Returns
The number as read from the bytes.

References bytesToUInt16().

Referenced by crawlservpp::Data::PickleDict::writeTo().

◆ bytesToInt32()

std::int32_t crawlservpp::Helper::Bytes::bytesToInt32 ( const Bytes bytes,
std::size_t &  pos 
)
inline

Retrieve a signed 32-bit number from a vector of bytes.

Parameters
bytesConstant reference to a vector containing the bytes.
posReference to the start position of the number contained in the bytes. The position will be updated after reading the number from the bytes.
Returns
The number as read from the bytes.

References bytesToUInt32().

Referenced by crawlservpp::Data::PickleDict::writeTo().

◆ bytesToInt64() [1/2]

std::int64_t crawlservpp::Helper::Bytes::bytesToInt64 ( const Bytes bytes,
std::size_t &  pos 
)
inline

Retrieve a signed 64-bit number from a vector of bytes.

Parameters
bytesConstant reference to a vector containing the bytes.
posReference to the start position of the number contained in the bytes. The position will be updated after reading the number from the bytes.
Returns
The number as read from the bytes.

References bytesToUInt64().

Referenced by crawlservpp::Data::PickleDict::writeTo().

◆ bytesToInt64() [2/2]

std::int64_t crawlservpp::Helper::Bytes::bytesToInt64 ( const Bytes bytes,
std::size_t &  pos,
std::size_t  len 
)
inline

Retrieve a signed 64-bit number from a vector of bytes.

Parameters
bytesConstant reference to a vector containing the bytes.
posReference to the start position of the number contained in the bytes. The position will be updated after reading the number from the bytes.
lenThe actual number of bytes used by the number.
Returns
The number as read from the bytes.

References bytesToUInt64().

◆ bytesToUInt16()

std::uint16_t crawlservpp::Helper::Bytes::bytesToUInt16 ( const Bytes bytes,
std::size_t &  pos 
)
inline

Retrieve an unsigned 16-bit number from a vector of bytes.

Parameters
bytesConstant reference to a vector containing the bytes.
posReference to the start position of the number contained in the bytes. The position will be updated after reading the number from the bytes.
Returns
The number as read from the bytes.

References first, isBigEndian(), oneByteBits, crawlservpp::Helper::Queue::reverse(), second, and sizeTwo.

Referenced by bytesToInt16(), and crawlservpp::Data::PickleDict::writeTo().

◆ bytesToUInt32()

std::uint32_t crawlservpp::Helper::Bytes::bytesToUInt32 ( const Bytes bytes,
std::size_t &  pos 
)
inline

Retrieve an unsigned 32-bit number from a vector of bytes.

Parameters
bytesConstant reference to a vector containing the bytes.
posReference to the start position of the number contained in the bytes. The position will be updated after reading the number from the bytes.
Returns
The number as read from the bytes.

References first, fourth, isBigEndian(), oneByteBits, crawlservpp::Helper::Queue::reverse(), second, sizeFour, third, threeBytesBits, and twoBytesBits.

Referenced by bytesToInt32(), and crawlservpp::Data::PickleDict::writeTo().

◆ bytesToUInt64() [1/2]

std::uint64_t crawlservpp::Helper::Bytes::bytesToUInt64 ( const Bytes bytes,
std::size_t &  pos 
)
inline

Retrieve an unsigned 64-bit number from a vector of bytes.

Parameters
bytesConstant reference to a vector containing the bytes.
posReference to the start position of the number contained in the bytes. The position will be updated after reading the number from the bytes.
Returns
The number as read from the bytes.

References eighth, fifth, first, fiveBytesBits, fourBytesBits, fourth, isBigEndian(), oneByteBits, crawlservpp::Helper::Queue::reverse(), second, sevenBytesBits, seventh, sixBytesBits, sixth, sizeEight, third, threeBytesBits, and twoBytesBits.

Referenced by bytesToInt64(), and crawlservpp::Data::PickleDict::writeTo().

◆ bytesToUInt64() [2/2]

std::uint64_t crawlservpp::Helper::Bytes::bytesToUInt64 ( const Bytes bytes,
std::size_t &  pos,
std::size_t  len 
)
inline

Retrieve an unsigned 64-bit number from a vector of bytes.

Parameters
bytesConstant reference to a vector containing the bytes.
posReference to the start position of the number contained in the bytes. The position will be updated after reading the number from the bytes.
lenThe actual number of bytes used by the number.
Returns
The number as read from the bytes.

References eighth, fifth, first, fiveBytesBits, fourBytesBits, fourth, isBigEndian(), oneByteBits, crawlservpp::Helper::Queue::reverse(), second, sevenBytesBits, seventh, sixBytesBits, sixth, sizeEight, third, threeBytesBits, and twoBytesBits.

◆ byteToHexString()

std::string crawlservpp::Helper::Bytes::byteToHexString ( std::uint8_t  byte)
inline

Converts a byte to a string containing the byte in hexadecimal format.

Parameters
byteThe byte to convert into a string.
Returns
The string containing a hexadecimal representation of the byte in the format 0xHH where HH is the hexadecimal value of the byte.

Referenced by charToString(), and crawlservpp::Data::PickleDict::writeTo().

◆ charToString()

std::string crawlservpp::Helper::Bytes::charToString ( char  c)
inline

Converts a character to a string.

If printable, the character will be simply converted into a string. If escapable, the string representation of its C escape sequence will be returned. Otherwise, its hexadecimal representation will be returned.

The resulting string will be between one and four characters long.

Parameters
cThe character to convert.
Returns
The resulting string.
See also
byteToHexString

References byteToHexString().

Referenced by crawlservpp::Data::PickleDict::writeTo().

◆ doubleToBytes()

std::array< std::uint8_t, sizeEight > crawlservpp::Helper::Bytes::doubleToBytes ( double  number)
inline

Converts a floating-point number with double precision to an array of four bytes.

Parameters
numberThe floating-point number to convert to bytes.
Returns
An array containing the resulting eight bytes.

References isFloatBigEndian(), and crawlservpp::Helper::Queue::reverse().

Referenced by crawlservpp::Data::PickleDict::writeTo().

◆ int16ToBytes()

std::array< std::uint8_t, sizeTwo > crawlservpp::Helper::Bytes::int16ToBytes ( std::int16_t  number)
inline

Converts an signed 16-bit number to an array of two bytes.

Parameters
numberThe number to convert to bytes.
Returns
An array containing the resulting two bytes.

References isBigEndian(), and crawlservpp::Helper::Queue::reverse().

Referenced by crawlservpp::Data::PickleDict::writeTo().

◆ int32ToBytes()

std::array< std::uint8_t, sizeFour > crawlservpp::Helper::Bytes::int32ToBytes ( std::int32_t  number)
inline

Converts an signed 32-bit number to an array of four bytes.

Parameters
numberThe number to convert to bytes.
Returns
An array containing the resulting four bytes.

References isBigEndian(), and crawlservpp::Helper::Queue::reverse().

Referenced by crawlservpp::Data::PickleDict::writeTo().

◆ int64ToBytes()

std::array< std::uint8_t, sizeEight > crawlservpp::Helper::Bytes::int64ToBytes ( std::int64_t  number)
inline

Converts a signed 64-bit number to an array of eight bytes.

Parameters
numberThe number to convert to bytes.
Returns
An array containing the resulting eight bytes.

References isBigEndian(), and crawlservpp::Helper::Queue::reverse().

Referenced by crawlservpp::Data::PickleDict::writeTo().

◆ isBigEndian()

bool crawlservpp::Helper::Bytes::isBigEndian ( )
inlinenoexcept

Returns whether the machine running this code uses big endianness.

Returns
True, if the machine running this code uses big endianness. False otherwise.

Referenced by bytesToUInt16(), bytesToUInt32(), bytesToUInt64(), int16ToBytes(), int32ToBytes(), int64ToBytes(), uInt16ToBytes(), uInt32ToBytes(), and uInt64ToBytes().

◆ isFloatBigEndian()

bool crawlservpp::Helper::Bytes::isFloatBigEndian ( )
inlinenoexcept

Returns whether the machine running this code uses big endianness for floating-point numbers.

Returns
True, if the machine running this code uses big endianness for floating-point numbers. False otherwise.

Referenced by bytesToDouble(), and doubleToBytes().

◆ uInt16ToBytes()

std::array< std::uint8_t, sizeTwo > crawlservpp::Helper::Bytes::uInt16ToBytes ( std::uint16_t  number)
inline

Converts an unsigned 16-bit number to an array of two bytes.

Parameters
numberThe number to convert to bytes.
Returns
An array containing the resulting two bytes.

References isBigEndian(), and crawlservpp::Helper::Queue::reverse().

Referenced by crawlservpp::Data::PickleDict::writeTo().

◆ uInt32ToBytes()

std::array< std::uint8_t, sizeFour > crawlservpp::Helper::Bytes::uInt32ToBytes ( std::uint32_t  number)
inline

Converts an unsigned 32-bit number to an array of four bytes.

Parameters
numberThe number to convert to bytes.
Returns
An array containing the resulting four bytes.

References isBigEndian(), and crawlservpp::Helper::Queue::reverse().

Referenced by crawlservpp::Data::PickleDict::writeTo().

◆ uInt64ToBytes()

std::array< std::uint8_t, sizeEight > crawlservpp::Helper::Bytes::uInt64ToBytes ( std::uint64_t  number)
inline

Converts an unsigned 64-bit number to an array of eight bytes.

Parameters
numberThe number to convert to bytes.
Returns
An array containing the resulting eight bytes.

References isBigEndian(), and crawlservpp::Helper::Queue::reverse().

Referenced by crawlservpp::Data::PickleDict::writeTo().

Variable Documentation

◆ eighth

constexpr auto crawlservpp::Helper::Bytes::eighth {7}

Index of the eighth byte.

Referenced by bytesToDouble(), and bytesToUInt64().

◆ fifth

constexpr auto crawlservpp::Helper::Bytes::fifth {4}

Index of the fifth byte.

Referenced by bytesToDouble(), and bytesToUInt64().

◆ first

◆ fiveBytesBits

constexpr auto crawlservpp::Helper::Bytes::fiveBytesBits {40}

Five bytes in bits.

Referenced by bytesToUInt64().

◆ fourBytesBits

constexpr auto crawlservpp::Helper::Bytes::fourBytesBits {32}

Four bytes in bits.

Referenced by bytesToUInt64().

◆ fourth

constexpr auto crawlservpp::Helper::Bytes::fourth {3}

Index of the fourth byte.

Referenced by bytesToDouble(), bytesToUInt32(), and bytesToUInt64().

◆ oneByteBits

constexpr auto crawlservpp::Helper::Bytes::oneByteBits {8}

One byte in bits.

Referenced by bytesToUInt16(), bytesToUInt32(), and bytesToUInt64().

◆ second

constexpr auto crawlservpp::Helper::Bytes::second {1}

Index of the second byte.

Referenced by bytesToDouble(), bytesToUInt16(), bytesToUInt32(), and bytesToUInt64().

◆ sevenBytesBits

constexpr auto crawlservpp::Helper::Bytes::sevenBytesBits {56}

Seven bytes in bits.

Referenced by bytesToUInt64().

◆ seventh

constexpr auto crawlservpp::Helper::Bytes::seventh {6}

Index of the seventh byte.

Referenced by bytesToDouble(), and bytesToUInt64().

◆ sixBytesBits

constexpr auto crawlservpp::Helper::Bytes::sixBytesBits {48}

Six bytes in bits.

Referenced by bytesToUInt64().

◆ sixth

constexpr auto crawlservpp::Helper::Bytes::sixth {5}

Index of the sixth byte.

Referenced by bytesToDouble(), and bytesToUInt64().

◆ sizeEight

constexpr auto crawlservpp::Helper::Bytes::sizeEight {8}

Size of eight bytes.

Referenced by bytesToDouble(), and bytesToUInt64().

◆ sizeFour

constexpr auto crawlservpp::Helper::Bytes::sizeFour {4}

Size of four bytes.

Referenced by bytesToUInt32().

◆ sizeTwo

constexpr auto crawlservpp::Helper::Bytes::sizeTwo {2}

Size of two bytes.

Referenced by bytesToUInt16().

◆ third

constexpr auto crawlservpp::Helper::Bytes::third {2}

Index of the third byte.

Referenced by bytesToDouble(), bytesToUInt32(), and bytesToUInt64().

◆ threeBytesBits

constexpr auto crawlservpp::Helper::Bytes::threeBytesBits {24}

Three bytes in bits.

Referenced by bytesToUInt32(), and bytesToUInt64().

◆ twoBytesBits

constexpr auto crawlservpp::Helper::Bytes::twoBytesBits {16}

Two bytes in bits.

Referenced by bytesToUInt32(), and bytesToUInt64().