Newer
Older
* Copyright (c) 2016-2017, Luca Fulchir<luca@fulchir.it>, All rights reserved.
*
* This file is part of "libRaptorQ".
*
* libRaptorQ is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* libRaptorQ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* and a copy of the GNU Lesser General Public License
* along with libRaptorQ. If not, see <http://www.gnu.org/licenses/>.
*/
#include "RaptorQ/v1/wrapper/CPP_RAW_API_void.hpp"
#include "RaptorQ/v1/RaptorQ.hpp"
namespace RaptorQ__v1 {
namespace Impl {
union RAPTORQ_LOCAL cast_enc {
void* const _raw;
Impl::Encoder<uint8_t*, uint8_t* >* const _8;
Impl::Encoder<uint16_t*, uint16_t*>* const _16;
Impl::Encoder<uint32_t*, uint32_t*>* const _32;
Impl::Encoder<uint64_t*, uint64_t*>* const _64;
cast_enc (void * raw) : _raw(raw) {}
};
union RAPTORQ_LOCAL cast_dec {
void* const _raw;
Impl::Decoder<uint8_t*, uint8_t* >* const _8;
Impl::Decoder<uint16_t*, uint16_t*>* const _16;
Impl::Decoder<uint32_t*, uint32_t*>* const _32;
Impl::Decoder<uint64_t*, uint64_t*>* const _64;
cast_dec (void * raw) : _raw(raw) {}
};
// check that we have the right type, else keep error.
static RaptorQ_type init_t (const RaptorQ_type type, const bool is_encoder)
{
switch (type) {
case RaptorQ_type::RQ_ENC_8:
return (is_encoder ? RaptorQ_type::RQ_ENC_8 : RaptorQ_type::RQ_NONE);
case RaptorQ_type::RQ_ENC_16:
return (is_encoder ? RaptorQ_type::RQ_ENC_16 : RaptorQ_type::RQ_NONE);
case RaptorQ_type::RQ_ENC_32:
return (is_encoder ? RaptorQ_type::RQ_ENC_32 : RaptorQ_type::RQ_NONE);
case RaptorQ_type::RQ_ENC_64:
return (is_encoder ? RaptorQ_type::RQ_ENC_64 : RaptorQ_type::RQ_NONE);
case RaptorQ_type::RQ_DEC_8:
return (is_encoder ? RaptorQ_type::RQ_NONE : RaptorQ_type::RQ_DEC_8);
case RaptorQ_type::RQ_DEC_16:
return (is_encoder ? RaptorQ_type::RQ_NONE : RaptorQ_type::RQ_DEC_16);
case RaptorQ_type::RQ_DEC_32:
return (is_encoder ? RaptorQ_type::RQ_NONE : RaptorQ_type::RQ_DEC_32);
case RaptorQ_type::RQ_DEC_64:
return (is_encoder ? RaptorQ_type::RQ_NONE : RaptorQ_type::RQ_DEC_64);
case RaptorQ_type::RQ_NONE:
break;
}
return RaptorQ_type::RQ_NONE;
}
////////////////
//// Encoder
/////////////////
Encoder_void::Encoder_void (const RaptorQ_type type,
const RaptorQ_Block_Size symbols,
const size_t symbol_size)
: _type (init_t (type, true))
{
switch (_type) {
case RaptorQ_type::RQ_ENC_8:
_encoder = new Encoder<uint8_t*, uint8_t*> (
static_cast<Block_Size> (symbols), symbol_size);
_encoder = new Encoder<uint16_t*, uint16_t*> (
static_cast<Block_Size> (symbols), symbol_size);
_encoder = new Encoder<uint32_t*, uint32_t*> (
static_cast<Block_Size> (symbols), symbol_size);
_encoder = new Encoder<uint64_t*, uint64_t*> (
static_cast<Block_Size> (symbols), symbol_size);
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
return;
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
break;
}
_encoder = nullptr;
}
Encoder_void::~Encoder_void()
{
switch (_type) {
case RaptorQ_type::RQ_ENC_8:
delete reinterpret_cast<Encoder<uint8_t*, uint8_t*>*> (_encoder);
break;
case RaptorQ_type::RQ_ENC_16:
delete reinterpret_cast<Encoder<uint16_t*, uint16_t*>*> (_encoder);
break;
case RaptorQ_type::RQ_ENC_32:
delete reinterpret_cast<Encoder<uint32_t*, uint32_t*>*> (_encoder);
break;
case RaptorQ_type::RQ_ENC_64:
delete reinterpret_cast<Encoder<uint64_t*, uint64_t*>*> (_encoder);
break;
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
break;
}
_type = RaptorQ_type::RQ_NONE;
_encoder = nullptr;
}
Encoder_void::operator bool() const
{
switch (_type) {
case RaptorQ_type::RQ_ENC_8:
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
break;
}
return false;
}
uint16_t Encoder_void::symbols() const
{
switch (_type) {
case RaptorQ_type::RQ_ENC_8:
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
break;
}
return 0;
}
size_t Encoder_void::symbol_size() const
{
switch (_type) {
case RaptorQ_type::RQ_ENC_8:
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
break;
}
return 0;
}
uint32_t Encoder_void::max_repair() const
Loading full blame...