OpenMS  2.7.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
Base64 Class Reference

Class to encode and decode Base64. More...

#include <OpenMS/FORMAT/Base64.h>

Collaboration diagram for Base64:
[legend]

Classes

union  Reinterpreter32_
 Internal class needed for type-punning. More...
 
union  Reinterpreter64_
 Internal class needed for type-punning. More...
 

Public Types

enum  ByteOrder { BYTEORDER_BIGENDIAN , BYTEORDER_LITTLEENDIAN }
 Byte order type. More...
 

Public Member Functions

 Base64 ()=default
 default constructor More...
 

Static Public Member Functions

template<typename FromType >
static void encode (std::vector< FromType > &in, ByteOrder to_byte_order, String &out, bool zlib_compression=false)
 Encodes a vector of floating point numbers to a Base64 string. More...
 
template<typename ToType >
static void decode (const String &in, ByteOrder from_byte_order, std::vector< ToType > &out, bool zlib_compression=false)
 Decodes a Base64 string to a vector of floating point numbers. More...
 
template<typename FromType >
static void encodeIntegers (std::vector< FromType > &in, ByteOrder to_byte_order, String &out, bool zlib_compression=false)
 Encodes a vector of integer point numbers to a Base64 string. More...
 
template<typename ToType >
static void decodeIntegers (const String &in, ByteOrder from_byte_order, std::vector< ToType > &out, bool zlib_compression=false)
 Decodes a Base64 string to a vector of integer numbers. More...
 
static void encodeStrings (const std::vector< String > &in, String &out, bool zlib_compression=false, bool append_null_byte=true)
 Encodes a vector of strings to a Base64 string. More...
 
static void decodeStrings (const String &in, std::vector< String > &out, bool zlib_compression=false)
 Decodes a Base64 string to a vector of (null-terminated) strings. More...
 
static void decodeSingleString (const String &in, QByteArray &base64_uncompressed, bool zlib_compression)
 Decodes a Base64 string to a QByteArray. More...
 

Static Private Member Functions

template<typename ToType >
static void decodeUncompressed_ (const String &in, ByteOrder from_byte_order, std::vector< ToType > &out)
 Decodes a Base64 string to a vector of floating point numbers. More...
 
template<typename ToType >
static void decodeCompressed_ (const String &in, ByteOrder from_byte_order, std::vector< ToType > &out)
 Decodes a compressed Base64 string to a vector of floating point numbers. More...
 
template<typename ToType >
static void decodeIntegersUncompressed_ (const String &in, ByteOrder from_byte_order, std::vector< ToType > &out)
 Decodes a Base64 string to a vector of integer numbers. More...
 
template<typename ToType >
static void decodeIntegersCompressed_ (const String &in, ByteOrder from_byte_order, std::vector< ToType > &out)
 Decodes a compressed Base64 string to a vector of integer numbers. More...
 

Static Private Attributes

static const char encoder_ []
 
static const char decoder_ []
 

Detailed Description

Class to encode and decode Base64.

Base64 supports two precisions: 32 bit (float) and 64 bit (double).


Class Documentation

◆ OpenMS::Base64::Reinterpreter32_

union OpenMS::Base64::Reinterpreter32_

Internal class needed for type-punning.

Collaboration diagram for Base64::Reinterpreter32_:
[legend]
Class Members
float f
UInt32 i

◆ OpenMS::Base64::Reinterpreter64_

union OpenMS::Base64::Reinterpreter64_

Internal class needed for type-punning.

Collaboration diagram for Base64::Reinterpreter64_:
[legend]
Class Members
double f
UInt64 i

Member Enumeration Documentation

◆ ByteOrder

enum ByteOrder

Byte order type.

Enumerator
BYTEORDER_BIGENDIAN 

Big endian type.

BYTEORDER_LITTLEENDIAN 

Little endian type.

Constructor & Destructor Documentation

◆ Base64()

Base64 ( )
default

default constructor

Member Function Documentation

◆ decode()

void decode ( const String in,
ByteOrder  from_byte_order,
std::vector< ToType > &  out,
bool  zlib_compression = false 
)
static

Decodes a Base64 string to a vector of floating point numbers.

You have to specify the byte order of the input and if it is zlib-compressed.

References Base64::decodeCompressed_(), and Base64::decodeUncompressed_().

◆ decodeCompressed_()

void decodeCompressed_ ( const String in,
ByteOrder  from_byte_order,
std::vector< ToType > &  out 
)
staticprivate

Decodes a compressed Base64 string to a vector of floating point numbers.

References Base64::BYTEORDER_BIGENDIAN, Base64::BYTEORDER_LITTLEENDIAN, OpenMS::endianize32(), OpenMS::endianize64(), and OPENMS_IS_BIG_ENDIAN.

Referenced by Base64::decode().

◆ decodeIntegers()

void decodeIntegers ( const String in,
ByteOrder  from_byte_order,
std::vector< ToType > &  out,
bool  zlib_compression = false 
)
static

Decodes a Base64 string to a vector of integer numbers.

You have to specify the byte order of the input and if it is zlib-compressed.

References Base64::decodeIntegersCompressed_(), and Base64::decodeIntegersUncompressed_().

◆ decodeIntegersCompressed_()

void decodeIntegersCompressed_ ( const String in,
ByteOrder  from_byte_order,
std::vector< ToType > &  out 
)
staticprivate

Decodes a compressed Base64 string to a vector of integer numbers.

References Base64::BYTEORDER_BIGENDIAN, Base64::BYTEORDER_LITTLEENDIAN, OpenMS::endianize32(), OpenMS::endianize64(), and OPENMS_IS_BIG_ENDIAN.

Referenced by Base64::decodeIntegers().

◆ decodeIntegersUncompressed_()

void decodeIntegersUncompressed_ ( const String in,
ByteOrder  from_byte_order,
std::vector< ToType > &  out 
)
staticprivate

Decodes a Base64 string to a vector of integer numbers.

References Base64::BYTEORDER_BIGENDIAN, Base64::BYTEORDER_LITTLEENDIAN, Base64::decoder_, and OPENMS_IS_BIG_ENDIAN.

Referenced by Base64::decodeIntegers().

◆ decodeSingleString()

static void decodeSingleString ( const String in,
QByteArray &  base64_uncompressed,
bool  zlib_compression 
)
static

Decodes a Base64 string to a QByteArray.

Parameters
inA String containing the Base64 encoded data
outA ByteArray containing the decoded data
zlib_compressionWhether the data should be decompressed with zlib after decoding in Base64

◆ decodeStrings()

static void decodeStrings ( const String in,
std::vector< String > &  out,
bool  zlib_compression = false 
)
static

Decodes a Base64 string to a vector of (null-terminated) strings.

You have to specify whether the Base64 string is zlib-compressed.

Parameters
inA String containing the Base64 encoded data
outA vector containing the decoded data (split at null "\0") bytes
zlib_compressionWhether the data should be decompressed with zlib after decoding in Base64

◆ decodeUncompressed_()

void decodeUncompressed_ ( const String in,
ByteOrder  from_byte_order,
std::vector< ToType > &  out 
)
staticprivate

Decodes a Base64 string to a vector of floating point numbers.

References Base64::BYTEORDER_BIGENDIAN, Base64::BYTEORDER_LITTLEENDIAN, Base64::decoder_, and OPENMS_IS_BIG_ENDIAN.

Referenced by Base64::decode().

◆ encode()

void encode ( std::vector< FromType > &  in,
ByteOrder  to_byte_order,
String out,
bool  zlib_compression = false 
)
static

Encodes a vector of floating point numbers to a Base64 string.

You can specify the byte order of the output and if it is zlib-compressed.

Note
in will be empty after this method

References Base64::BYTEORDER_BIGENDIAN, Base64::BYTEORDER_LITTLEENDIAN, Base64::encoder_, OpenMS::endianize32(), OpenMS::endianize64(), Base64::Reinterpreter64_::f, Base64::Reinterpreter32_::f, Base64::Reinterpreter64_::i, Base64::Reinterpreter32_::i, and OPENMS_IS_BIG_ENDIAN.

◆ encodeIntegers()

void encodeIntegers ( std::vector< FromType > &  in,
ByteOrder  to_byte_order,
String out,
bool  zlib_compression = false 
)
static

Encodes a vector of integer point numbers to a Base64 string.

You can specify the byte order of the output and if it is zlib-compressed.

Note
in will be empty after this method

References Base64::BYTEORDER_BIGENDIAN, Base64::BYTEORDER_LITTLEENDIAN, Base64::encoder_, OpenMS::endianize32(), OpenMS::endianize64(), and OPENMS_IS_BIG_ENDIAN.

◆ encodeStrings()

static void encodeStrings ( const std::vector< String > &  in,
String out,
bool  zlib_compression = false,
bool  append_null_byte = true 
)
static

Encodes a vector of strings to a Base64 string.

You can specify zlib-compression.

Parameters
inA vector of data to be encoded (String)
outA String containing the Base64 encoded data
zlib_compressionWhether the data should be compressed with zlib before encoding in Base64
append_null_byteWhether a null-byte should be appended after each of the Strings contained in the in vector
Note
Unless append_null_byte is false, will add a null byte ("\0") at the end of each input

Member Data Documentation

◆ decoder_

const char decoder_[]
staticprivate

◆ encoder_

const char encoder_[]
staticprivate