Skip to content

Milestones

List view

  • add a class/struct to deal with enocing decoding, the code is very similar template<typename Model> struct Z85 { typedef typename Model::return_type return_type ; template<typename Container> 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<typename __Iter> 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<typename __Iter> 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] ; } ) ; } } ;

    Overdue by 9 year(s)
    Due by October 23, 2015