crawlserv++  [under development]
Application for crawling and analyzing textual content of websites.
crawlservpp::Data::PickleDict Class Reference

Simple Python pickle dictionary. More...

#include <PickleDict.hpp>

Classes

class  Exception
 Class for Python pickle exceptions. More...
 

Construction

 PickleDict ()=default
 Default constructor. More...
 
 PickleDict (const Bytes &data)
 Constructor reading the bytes of a Python pickle. More...
 

Getters

std::optional< std::int64_t > getNumber (const std::string &key) const
 Gets a number from the dictionary, if avaible. More...
 
std::optional< double > getFloat (const std::string &key) const
 Gets a floating-point number from the dictionary, if avaible. More...
 
std::optional< std::string > getString (const std::string &key) const
 Gets a string from the dictionary, if avaible. More...
 

Setters

void setNumber (const std::string &key, std::int64_t value)
 Adds or overwrite a number in the dictionary. More...
 
void setFloat (const std::string &key, double value)
 Adds or overwrites a floating-point number in the dictionary. More...
 
void setString (const std::string &key, const std::string &value)
 Add or overwrites a string in the dictionary. More...
 

Reading and Writing

void readFrom (const Bytes &data)
 Creates a simple dictionary from Python pickle data. More...
 
void writeTo (Bytes &dataTo) const
 Writes dictionary to Python pickle data. More...
 

Detailed Description

Simple Python pickle dictionary.

Only pickles with protocol version 4 or higher are supported.

Note
Does not actually run Python pickle op-codes, only extracts data from, or writes its data to a simple Python pickle.
Warning
Only SHORT_BINSTRING and SHORT_BINUNICODE, i.e. strings up to a length of 255 are supported as key names. They need to be separated by MEMOIZE from their respective values in the Python pickle.

Constructor & Destructor Documentation

◆ PickleDict() [1/2]

crawlservpp::Data::PickleDict::PickleDict ( )
default

Default constructor.

◆ PickleDict() [2/2]

crawlservpp::Data::PickleDict::PickleDict ( const Bytes data)
inlineexplicit

Constructor reading the bytes of a Python pickle.

Parameters
dataThe bytes contained in a pickle.

References readFrom().

Member Function Documentation

◆ getFloat()

std::optional< double > crawlservpp::Data::PickleDict::getFloat ( const std::string &  key) const
inline

Gets a floating-point number from the dictionary, if avaible.

Parameters
keyThe key of the dictionary entry containing the floating-point number.
Returns
An optional containing the floating-point number, if it has been found in the dictionary.

Referenced by crawlservpp::Data::TopicModel::clear().

◆ getNumber()

std::optional< std::int64_t > crawlservpp::Data::PickleDict::getNumber ( const std::string &  key) const
inline

Gets a number from the dictionary, if avaible.

Parameters
keyThe key of the dictionary entry containing the number.
Returns
An optional containing the number, if it has been found in the dictionary.

Referenced by crawlservpp::Data::TopicModel::clear().

◆ getString()

std::optional< std::string > crawlservpp::Data::PickleDict::getString ( const std::string &  key) const
inline

Gets a string from the dictionary, if avaible.

Parameters
keyThe key of the dictionary entry containing the string.
Returns
An optional containing the string, if it has been found in the dictionary.

Referenced by crawlservpp::Data::TopicModel::clear(), and writeTo().

◆ readFrom()

void crawlservpp::Data::PickleDict::readFrom ( const Bytes data)
inline

Creates a simple dictionary from Python pickle data.

Only Python pickles with protocol version 4 or higher are supported.

Note
Does not actually run Python pickle op-codes, only extracts data from, or writes its data to a simple Python pickle.
Parameters
dataConstant reference to a vector containing the bytes of the Python pickle.
Exceptions
PickleDict::Exceptionif the data could not be read correctly.
Warning
Only SHORT_BINSTRING and SHORT_BINUNICODE, i.e. strings up to a length of 255 are supported as key names. They need to be separated by MEMOIZE from their respective values in the Python pickle.

Referenced by PickleDict().

◆ setFloat()

void crawlservpp::Data::PickleDict::setFloat ( const std::string &  key,
double  value 
)
inline

Adds or overwrites a floating-point number in the dictionary.

Parameters
keyThe key of the value.
valueThe corresponding value.

Referenced by crawlservpp::Data::TopicModel::clear(), and writeTo().

◆ setNumber()

void crawlservpp::Data::PickleDict::setNumber ( const std::string &  key,
std::int64_t  value 
)
inline

Adds or overwrite a number in the dictionary.

Parameters
keyThe key of the value.
valueThe corresponding value.

Referenced by crawlservpp::Data::TopicModel::clear(), and writeTo().

◆ setString()

void crawlservpp::Data::PickleDict::setString ( const std::string &  key,
const std::string &  value 
)
inline

Add or overwrites a string in the dictionary.

Parameters
keyThe key of the value.
valueThe corresponding value.

Referenced by crawlservpp::Data::TopicModel::clear(), and writeTo().

◆ writeTo()

void crawlservpp::Data::PickleDict::writeTo ( Bytes dataTo) const
inline

Writes dictionary to Python pickle data.

Python pickle protocol version 4 will be used and the data will be written to one single frame.

Parameters
dataToReference to a vector which will contain the bytes of the data after writing. The vector will be cleared before writing begins (although no memory will be freed).

References crawlservpp::Helper::Container::append(), crawlservpp::Helper::Bytes::bytesToDouble(), crawlservpp::Helper::Bytes::bytesToInt16(), crawlservpp::Helper::Bytes::bytesToInt32(), crawlservpp::Helper::Bytes::bytesToInt64(), crawlservpp::Helper::Bytes::bytesToUInt16(), crawlservpp::Helper::Bytes::bytesToUInt32(), crawlservpp::Helper::Bytes::bytesToUInt64(), crawlservpp::Helper::Bytes::byteToHexString(), crawlservpp::Helper::Bytes::charToString(), crawlservpp::Helper::Bytes::doubleToBytes(), getString(), crawlservpp::Helper::Bytes::int16ToBytes(), crawlservpp::Helper::Bytes::int32ToBytes(), crawlservpp::Helper::Bytes::int64ToBytes(), crawlservpp::Helper::Utf8::length(), crawlservpp::Helper::Container::moveInto(), crawlservpp::Data::pickleBase, crawlservpp::Data::pickleEightBytes, crawlservpp::Data::pickleFourBytes, crawlservpp::Data::pickleHeadSize, crawlservpp::Data::pickleMaxUFourByteNumber, crawlservpp::Data::pickleMaxUOneByteNumber, crawlservpp::Data::pickleMaxUTwoByteNumber, crawlservpp::Data::pickleMinFrameSize, crawlservpp::Data::pickleMinSize, crawlservpp::Data::pickleNineBytes, crawlservpp::Data::pickleOneByte, crawlservpp::Data::pickleProtoByte, crawlservpp::Data::pickleProtocolVersion, crawlservpp::Data::pickleTwoBytes, crawlservpp::Data::pickleVersionByte, setFloat(), setNumber(), setString(), crawlservpp::Helper::Bytes::uInt16ToBytes(), crawlservpp::Helper::Bytes::uInt32ToBytes(), and crawlservpp::Helper::Bytes::uInt64ToBytes().

Referenced by crawlservpp::Data::TopicModel::clear().


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