Newer
Older
#ifndef __VEREIGN_ENCODING_HEX_HH
#define __VEREIGN_ENCODING_HEX_HH
#include <vereign/bytes/buffer.hh>
#include <string>
namespace vereign::encoding::hex {
/**
* Encodes bytes in hexadecimal.
*
* Example:
* @code
* bytes::Buffer encoded;
* encoding::hex::Decode(bytes::View("foobar"), encoded);
*
* assert(encoded.View().String() == "666f6f626172");
* @endcode
*
* @param src The bytes that will be encoded.
* @param encoded The buffer where the encoded bytes will be written.
*/
void Encode(bytes::View src, bytes::Buffer& encoded);
/**
* Decodes hexadecimal encoded bytes.
*
* Example:
* @code
* bytes::Buffer decoded;
* encoding::hex::Decode(bytes::View("666f6f626172"), decoded);
*
* assert(decoded.View().String() == "foobar");
* @endcode
*
* @param src The bytes that will be decoded.
* @param encoded The buffer where the decoded bytes will be written.
*/
void Decode(bytes::View src, bytes::Buffer& decoded);
/**
* Encodes bytes in hexadecimal in reverse order.
*
* Example:
* @code
* bytes::Buffer encoded;
* encoding::hex::Decode(bytes::View("foobar"), encoded);
*
* assert(encoded.View().String() == "7261626f6f66");
* @endcode
*
* @param src The bytes that will be encoded.
* @param encoded The buffer where the encoded bytes will be written.
*/
void EncodeReverse(bytes::View src, bytes::Buffer& encoded);
} // vereign::encoding::hex
#endif // __VEREIGN_ENCODING_HEX_HH