add a class/struct to deal with enocing decoding, the code is very similar
template
struct Z85 {
typedef typename Model::return_type return_type ;
template
boost::optional<return_type> operator()( Container &data) {
booost::optional<return_type> encoded ;
if (data.size() % Model::size) { //According to algorithm stop processing , not possible
return encoded; //instead of throwing exception can return uninitialized string
}
encoded = return_type();
std::function<void (Container::iterator, Container::iterator) > func =
[&] (Container::iterator b , Container::iterator e)
{
if ( b==e) {
return;
}
uint32_t value = Model::accumulate(b,e) ;
uint divisor= boost::math::pow<Model::exp>(Model::base);
while(divisor) {
//less performance then preallocated string but sufice for now
//TODO: add extractor_function to encode/decode structs
//char c = VALID_Z85_CHARS [value / divisor % Model::base] ;
//encoded->push_back(c);
//divisor /=Model::base ;
}
func(e , e+Model::size > data.end() ? e : e+Model::size ) ;
return;
} ;
func(data.begin(),data.begin()+Model::size) ;
}
} ;
struct encode {
consexpr const int base = 85 ;
consexpr const int exp = 4 ;
consexpr const int size = 4 ;
template
uint32_t accumulate(__Iter b, __Iter e ) {
return std::accumulate(b,e, 0 , [] (uint32_t v, uint8_t x) { return v * 256 + x ; } ) ;
}
} ;
struct decode {
consexpr const int base = 256 ;
consexpr const int exp = 3 ;
consexpr const int size = 5 ;
template
uint32_t accumulate(__Iter b, __Iter e ) {
return std::accumulate(b,e, 0 , [] (uint32_t v, uint8_t x) { return v * 85 + decoder[x-32] ; } ) ;
}
} ;
List view
0 issues of 0 selected
There are no open issues in this milestone
Add issues to milestones to help organize your work for a particular release or project. Find and add issues with no milestones in this repo.