Qx v0.5.7
Qt Extensions Library
Loading...
Searching...
No Matches
Qx::Base85 Class Reference

The Base85 class provides a Base85 encoded string. More...

#include <qx/core/qx-base85.h>

Public Member Functions

 Base85 ()
 
QByteArrayView data () const
 
QByteArray decode ()
 
const Base85Encodingencoding () const
 
bool isEmpty ()
 
bool isNull ()
 
bool operator!= (const Base85 &other) const
 
bool operator== (const Base85 &other) const
 
qsizetype size () const
 
QString toString ()
 

Static Public Member Functions

static Base85 encode (const QByteArray &data, const Base85Encoding *enc)
 
static Base85 fromEncoded (QAnyStringView base85, const Base85Encoding *enc, Base85ParseError *error=nullptr)
 

Detailed Description

Base85, sometimes referred to by the Adobe specific variant Ascii85, is a form of binary-to-text encoding in which sets of 5 ASCII characters are used to represent equivalent sets of 4 bytes of binary data. This results in the encoded data generally being 20% larger than the original, though some specific encodings support minimal compression techniques.

This encoding format is useful for passing arbitrary binary data over communication protocols that only support single byte, human-readable (English) text, and likely interpret non-glyph characters as control characters, making it impossible to transmit raw data directly.

The encoding gets its name from the fact that each 'digit' of a Base85 encoded string is one of 85 ASCII characters, comparable to how Base16 is composed of the 16 digits 0-9 and A-F. The original Base85 encoding uses ASCII characters 0x21 ('!') through 0x75 ('u'), though it is possible to use other characters that aren't necessarily sequential.

Note
Base85 strings with prefix/suffix markers (e.g. "xbtoa Begin", "xbtoa End", "~>") are not supported. They must be handled independently of the actual payload when creating a Base85 instance from a pre-encoded string, and they will not be added to encoded strings created with encode().
See also
Base85Encoding, Ascii85 (on Wikipedia).

Constructor & Destructor Documentation

◆ Base85()

Qx::Base85::Base85 ( )

Constructs a null Base85 encoded string with no encoding set.

Member Function Documentation

◆ data()

QByteArrayView Qx::Base85::data ( ) const

Returns a view of the encoded data.

See also
toString().

◆ decode()

QByteArray Qx::Base85::decode ( )

Decodes the Base85 string to binary data using the same encoding that was used to encode it and returns it as a QByteArray.

See also
encode().

◆ encode()

Base85 Qx::Base85::encode ( const QByteArray & data,
const Base85Encoding * enc )
static

Encodes data as a Base85 string in accordance with the specific encoding enc and returns it, or a null Base85 if enc is not valid.

Warning
The caller must be able to guarantee that enc will not be deleted as long as the Base85 exists and may have its methods used.
See also
decode(), fromString(), and Base85Encoding::isValid().

◆ encoding()

const Base85Encoding * Qx::Base85::encoding ( ) const

Returns a pointer to the encoding used to create this Base85.

See also
Base85Encoding.

◆ fromEncoded()

Base85 Qx::Base85::fromEncoded ( QAnyStringView base85,
const Base85Encoding * enc,
Base85ParseError * error = nullptr )
static

Parses base85 as a Base85 string that was encoded with enc and creates a Base85 object from it. Any whitespace within the original data will not be present in the resultant object.

Returns a valid (non-null) Base85 string if the parsing succeeds. If it fails, the returned string will be null, and the optional error variable will contain further details about the error.

Warning
The caller must be able to guarantee that enc will not be deleted as long as the Base85 exists and may have its methods used.
See also
fromString(), Base85ParseError, isNull(), and encodedData().

◆ isEmpty()

bool Qx::Base85::isEmpty ( )

Returns true if the encoded string is empty; otherwise, returns false.

See also
isNull().

◆ isNull()

bool Qx::Base85::isNull ( )

Returns true if the encoded string is null; otherwise, returns false.

See also
isEmpty().

◆ operator!=()

bool Qx::Base85::operator!= ( const Base85 & other) const

Returns true if this Base85 string and other Base85 string are not the same; otherwise, returns false.

◆ operator==()

bool Qx::Base85::operator== ( const Base85 & other) const

Returns true if this Base85 string and other Base85 string are the same; otherwise, returns false.

◆ size()

qsizetype Qx::Base85::size ( ) const

Returns the size of the encoded data.

◆ toString()

QString Qx::Base85::toString ( )

Returns the UTF-16 equivalent of the encoded data.

See also
fromString().

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