Mercurial > hg > piper-cpp
view ext/base-n/README.md @ 185:3eb00e5c76c4
Pull step & block size out into framing struct, return in config
Update the C++ code to separate out the framing parameters (step and
block size) from the configuration structure into their own structure,
as in the latest schema, and to return the accepted framing params in
the configuration response.
This also implies that the plugin stub (which adapts Piper API
back to Vamp) makes a note of the returned values,
making them available via its own getPreferredStep/BlockSize
so that the host can retry the initialise call in the case where it
failed for having the wrong values first time.
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Fri, 03 Feb 2017 16:23:21 +0000 |
parents | bf8e3e7dd7de |
children |
line wrap: on
line source
base-n provides encoding/decoding support for BaseX encoding schemes accessible through a standard STL-like iterator interface. Standard Base16, Base32, and Base64 are available out-of-the-box. Adding or modifying custom schemes is supported. # Usage overview # base-n is a small, single-header library which provides standard Base16, Base32, Base64, and custom Base-N encoding support. The main functionality is delivered by the following functions in `bn` namespace: ``` template<class Iter1, class Iter2> void encode_b16(Iter1 start, Iter1 end, Iter2 out); template<class Iter1, class Iter2> void encode_b32(Iter1 start, Iter1 end, Iter2 out); template<class Iter1, class Iter2> void encode_b64(Iter1 start, Iter1 end, Iter2 out); template<class Iter1, class Iter2> void decode_b16(Iter1 start, Iter1 end, Iter2 out); template<class Iter1, class Iter2> void decode_b32(Iter1 start, Iter1 end, Iter2 out); template<class Iter1, class Iter2> void decode_b64(Iter1 start, Iter1 end, Iter2 out); ``` In order to encode and decode data in `std::string` variable `in`, you can do the following: ``` bn::encode_b64(in.begin(), in.end(), back_inserter(encoded)); bn::decode_b64(encoded.begin(), encoded.end(), ostream_iterator<char>(cout, "")); ``` Should you find yourself lacking some encoding scheme or the default character mapping rules are not good for your use case, you can easily provide your own encoder. For that, you need to define a struct type which will describe the new encoding. Sample below: ``` struct b8_custom { static size_t group_length() { return 3; } static char encode(int index) { const char* const dictionary = "01234567"; assert(index < strlen(dictionary)); return dictionary[index]; } static char decode(char c) { if (c >= '0' && c <= '7') { return c - '0'; } return -1; } }; ... string encoded; bn::impl::encode<b8_custom>(in.begin(), in.end(), back_inserter(encoded)); bn::impl::decode<b8_custom>(encoded.begin(), encoded.end(), ostream_iterator<char>(cout, "")); ``` For a full working example, see `basen_example.cpp` file in `example` directory.