AndroMeta  2.0.0
Static Public Member Functions
Meta::MEncoder Class Reference

Encoding/decoding to and from binary format, compresssion/decompression, and save/open utility functions. More...

#include <MEncoder.h>

List of all members.

Static Public Member Functions

static bool open (const mstr &path, mvar &out, bool config=false)
static bool save (const mstr &path, const mvar &in, bool config=false, const mstr &tempPath="")
static char * pack (const mvar &in, size_t &length)
static char * pack (const mvar &in, char *buffer, size_t &size, size_t &pos, bool resize=false)
static void unpack (mvar &out, char *buffer)
static void unpack (mvar &out, char *buffer, size_t &pos)
static void compress (char *in, size_t inSize, char *out, size_t &outSize)
static char * compress (char *in, size_t inSize, size_t &outSize)
static char * decompress (char *in, size_t inSize, char *out, size_t &outSize, bool resize)
static char * decompress (char *in, size_t inSize, size_t &outSize)
static void encode (const mvar &in, mvar &out)
static void decode (const mvar &in, mvar &out)
static mstr checksum (const char *buffer)
static mstr generateKey (const mstr &user, const mstr &password)

Detailed Description

Encoding/decoding to and from binary format, compresssion/decompression, and save/open utility functions.

Also include methods for reading config files, and computing checksums.


Member Function Documentation

static mstr Meta::MEncoder::checksum ( const char *  buffer) [static]

Compute an MD5 checksum using the RSA Data Security, Inc. MD5 Message-Digest Algorithm.

Parameters:
bufferInput buffer.
Returns:
The MD5 checksum.
static void Meta::MEncoder::compress ( char *  in,
size_t  inSize,
char *  out,
size_t &  outSize 
) [static]

Compress binary data from an input buffer into an existing output buffer.

Parameters:
inThe input buffer.
inSizeThe size of the binary segment to be compressed within the input buffer.
outThe output buffer.
outSizeOn input, the total length of the output buffer, on output the length of buffer that the compressed data segment occupies.
static char* Meta::MEncoder::compress ( char *  in,
size_t  inSize,
size_t &  outSize 
) [static]

Compress binary data into a newly allocated buffer.

Parameters:
inThe input buffer.
inSizeThe size of the binary segment to be compressed within the input buffer.
outSize.On output, the length of the compressed data.
Returns:
The newly created buffer containing the compressed data. User is responsible for deallocation via free().
static void Meta::MEncoder::decode ( const mvar in,
mvar out 
) [static]

Decompress and decode an input mvar into an output mvar.

Parameters:
inThe input mvar in compressed binary format.
outThe decoded output mvar.
static char* Meta::MEncoder::decompress ( char *  in,
size_t  inSize,
char *  out,
size_t &  outSize,
bool  resize 
) [static]

Decompress an input buffer into an existing output buffer.

Parameters:
inThe input buffer.
inSizeThe length of the compressed data within the input buffer.
outThe output buffer to decompress into, allocated with malloc().
outSize.On input, the total length of the output buffer. On output, the length of the decompressed data within the output buffer.
resizetrue if out buffer should be resized as needed.
Returns:
A pointer to the out buffer -- location may have changed after resizing.
static char* Meta::MEncoder::decompress ( char *  in,
size_t  inSize,
size_t &  outSize 
) [static]

Decompress an input buffer into a newly allocated buffer.

Parameters:
inThe input buffer.
inSizeThe length of the compressed data within the input buffer.
outSize.On input, the total length of the output buffer. On output, the length of the decompressed data within the output buffer.
Returns:
The newly created buffer containing the decompressed data. User is responsible for deallocation via free().
static void Meta::MEncoder::encode ( const mvar in,
mvar out 
) [static]

Pack and compress an input mvar into a binary output mvar.

Parameters:
inThe input mvar.
outThe output mvar to encode and compress into.
static mstr Meta::MEncoder::generateKey ( const mstr user,
const mstr password 
) [static]

Generate a key for user with the specified password. A given user and password always generates the same key.

Returns:
The generated key.
static bool Meta::MEncoder::open ( const mstr path,
mvar out,
bool  config = false 
) [static]

Open an mvar which has been saved to a file in compressed binary format (or plaintext in the case of a config file).

Parameters:
pathThe path of the file to open.
outStores the opened mvar in out.
configtrue if this is a config file (which is not in binary format). Config files entail extra handling such as reading environment variables embedded in strings.
Returns:
true on success.
static char* Meta::MEncoder::pack ( const mvar in,
size_t &  length 
) [static]

Pack an mvar into a newly allocated buffer.

Parameters:
inThe input mvar to pack.
lengthThe output length of the buffer.
Returns:
A newly allocated buffer which holds binary-packed mvar. User is responsible for deallocating the buffer with free().
static char* Meta::MEncoder::pack ( const mvar in,
char *  buffer,
size_t &  size,
size_t &  pos,
bool  resize = false 
) [static]

Pack an mvar into an existing buffer, optionally resizing the buffer as needed. If buffer is not large enough to accomodate the packed mvar and resize is false, an MError is thrown.

Parameters:
inThe input mvar to pack.
bufferAn existing buffer allocated with malloc().
sizeOn input the size of the existing buffer. On output, the size of the buffer after any resizing.
posOn input, the pack start position within the buffer. On output, the ending position.
resizetrue if buffer may be resized as needed.
Returns:
A pointer to the buffer after packing -- location may have changed after resizing.
static bool Meta::MEncoder::save ( const mstr path,
const mvar in,
bool  config = false,
const mstr tempPath = "" 
) [static]

Save an mvar as compressed binary format to a file (or write as plaintext in the case of a config file). The file is atomically saved to the specified path.

Parameters:
pathThe path to the filename to create.
inThe input mvar to save.
configtrue if this is config file and is to be saved as plaintext (in MML code).
tempPathThe path in which to store temporary files in order to save the file atomically. Uses the mTempPath arg if tempPath is empty.
static void Meta::MEncoder::unpack ( mvar out,
char *  buffer 
) [static]

Unpack an encoded mvar in buffer into output mvar.

Parameters:
outThe output mvar to unpack into.
bufferThe input buffer which holds the packed mvar.
static void Meta::MEncoder::unpack ( mvar out,
char *  buffer,
size_t &  pos 
) [static]

Unpack an encoded mvar in buffer into an output mvar.

Parameters:
outThe output mvar to unpack into.
bufferThe input buffer which holds the packed mvar.
posOn input the start position within the buffer. On output, the position at which the packed mvar ends.

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