Newer
Older
* Copyright (c) 2015-2018, Luca Fulchir<luca@fulchir.it>, All rights reserved.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
*
* 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_RFC_API_void.hpp"
#include "RaptorQ/v1/RFC.hpp"
#include <cmath>
#include <memory>
#include <utility>
/////////////////////
//
// These templates are just a wrapper around the
// functionalities offered by the RaptorQ__v1::Impl namespace
// So if you want to see what the algorithm looks like,
// you are in the wrong place
//
/////////////////////
namespace RFC6330__v1 {
namespace Impl {
// quic "casting" to avoid really long, repetitive lines.
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()
{
switch (_type) {
case RaptorQ_type::RQ_ENC_8:
delete reinterpret_cast<Impl::Encoder<uint8_t*, uint8_t*> *>(_encoder);
break;
case RaptorQ_type::RQ_ENC_16:
delete reinterpret_cast<Impl::Encoder<uint16_t*, uint16_t*>*>(_encoder);
break;
case RaptorQ_type::RQ_ENC_32:
delete reinterpret_cast<Impl::Encoder<uint32_t*, uint32_t*>*>(_encoder);
break;
case RaptorQ_type::RQ_ENC_64:
delete reinterpret_cast<Impl::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::Encoder_void (const RaptorQ_type type, const void* data_from,
const void* data_to,
const uint16_t min_subsymbol_size,
const uint16_t symbol_size,
: _type (init_t (type, true))
{
_encoder = nullptr;
switch (_type) {
case RaptorQ_type::RQ_ENC_8:
_encoder = new Impl::Encoder<uint8_t*, uint8_t*> (
reinterpret_cast<uint8_t*> (const_cast<void*>(data_from)),
reinterpret_cast<uint8_t*> (const_cast<void*>(data_to)),
min_subsymbol_size,
break;
case RaptorQ_type::RQ_ENC_16:
_encoder = new Impl::Encoder<uint16_t*, uint16_t*> (
reinterpret_cast<uint16_t*> (const_cast<void*>(data_from)),
reinterpret_cast<uint16_t*> (const_cast<void*>(data_to)),
min_subsymbol_size,
break;
case RaptorQ_type::RQ_ENC_32:
_encoder = new Impl::Encoder<uint32_t*, uint32_t*> (
reinterpret_cast<uint32_t*> (const_cast<void*>(data_from)),
reinterpret_cast<uint32_t*> (const_cast<void*>(data_to)),
min_subsymbol_size,
break;
case RaptorQ_type::RQ_ENC_64:
_encoder = new Impl::Encoder<uint64_t*, uint64_t*> (
reinterpret_cast<uint64_t*> (const_cast<void*>(data_from)),
reinterpret_cast<uint64_t*> (const_cast<void*>(data_to)),
min_subsymbol_size,
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
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;
}
}
Encoder_void::operator bool() const
{
const cast_enc _enc (_encoder);
switch (_type) {
case RaptorQ_type::RQ_ENC_8:
return static_cast<bool> (_enc._8);
case RaptorQ_type::RQ_ENC_16:
return static_cast<bool> (_enc._16);
case RaptorQ_type::RQ_ENC_32:
return static_cast<bool> (_enc._32);
case RaptorQ_type::RQ_ENC_64:
return static_cast<bool> (_enc._64);
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;
}
RFC6330_OTI_Common_Data Encoder_void::OTI_Common() const
{
const cast_enc _enc (_encoder);
switch (_type) {
case RaptorQ_type::RQ_ENC_8:
return _enc._8->OTI_Common();
case RaptorQ_type::RQ_ENC_16:
return _enc._16->OTI_Common();
case RaptorQ_type::RQ_ENC_32:
return _enc._32->OTI_Common();
case RaptorQ_type::RQ_ENC_64:
return _enc._64->OTI_Common();
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;
}
Loading full blame...