/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ /* vi: set expandtab shiftwidth=4 tabstop=4: */ /** * \file *
* High Performance Base85 Encoder / Decoder * * Copyright © 2006,2007 Nick Galbreath -- nickg [at] modp [dot] com * All rights reserved. * * http://code.google.com/p/stringencoders/ * * Released under bsd license. See modp_b85.c for details. ** * This provides a endian-safe base85 encode/decode operations. This * means, the result will be the same on x86 or ibm/sparc chips. * * (Note: making it endian-specifc only results in a 5% savings in * the decode operation, so why bother) */ #ifndef COM_MODP_STRINGENCODERS_B85 #define COM_MODP_STRINGENCODERS_B85 #ifdef __cplusplus #define BEGIN_C extern "C" { #define END_C } #else #define BEGIN_C #define END_C #endif BEGIN_C /** * base 85 encode * * \param[out] dest should have at least b85fast_encode_len memory allocated * \param[in] src input string * \param[in] len input string length, must be a multiple of 4 * \return the strlen of the destination, or -1 if error */ int modp_b85_encode(char* dest, const char* src, int len); /** * Base 85 decode * * \param[out] dest -- destination locations. May equal input. * \param[in] src -- source b85data * \param len -- length of source * \return -1 on decoding error, length of output otherwise * No ending null is added */ int modp_b85_decode(char* dest, const char* src, int len); /** * Returns the amount of memory to allocate for encoding the input * string. * */ #define modp_b85_encode_len(A) ((A + 3) / 4 * 5 + 1) /** * Return output strlen, without a NULL */ #define modp_b85_encode_strlen(A) ((A + 3) / 4 * 5) /** * Return the amount of memory to allocate for decoding a base 85 * encoded string. * */ #define modp_b85_decode_len(A) ((A + 4) / 5 * 4) END_C #ifdef __cplusplus #include