Newer
Older
1
2
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2015-2016, 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/C_RAW_API.h"
#include "RaptorQ/v1/RaptorQ.hpp"
#include <future>
#include <utility>
struct RAPTORQ_LOCAL RaptorQ_ptr
{
void *ptr;
const RaptorQ_type type;
RaptorQ_ptr (const RaptorQ_type _type) : ptr (nullptr), type (_type) {}
};
typedef enum {
RQ_FUTURE_ENCODER = 1,
RQ_FUTURE_DECODER = 2
} RAPTORQ_LOCAL RaptorQ_Future_Type;
struct RAPTORQ_LOCAL RaptorQ_future
{
const RaptorQ_Future_Type type;
RaptorQ_future (const RaptorQ_Future_Type t)
:type (t) {}
};
struct RAPTORQ_LOCAL RaptorQ_future_enc
{
const struct RaptorQ_future base;
std::future<RaptorQ__v1::Error> f;
RaptorQ_future_enc ()
:base (RaptorQ_Future_Type::RQ_FUTURE_ENCODER) {}
};
struct RAPTORQ_LOCAL RaptorQ_future_dec
{
const struct RaptorQ_future base;
std::future<std::pair<RaptorQ__v1::Error, uint16_t>> f;
RaptorQ_future_dec ()
:base (RaptorQ_Future_Type::RQ_FUTURE_DECODER) {}
};
// precomputation caching
static RaptorQ_Compress RAPTORQ_LOCAL v1_supported_compressions();
static RaptorQ_Compress RAPTORQ_LOCAL v1_get_compression();
static bool RAPTORQ_LOCAL v1_set_compression (
const RaptorQ_Compress compression);
static size_t RAPTORQ_LOCAL v1_shared_cache_size (const size_t shared_cache);
static size_t RAPTORQ_LOCAL v1_local_cache_size (const size_t local_cache);
static size_t RAPTORQ_LOCAL v1_get_shared_cache_size ();
static size_t RAPTORQ_LOCAL v1_get_local_cache_size ();
// constructors
struct RaptorQ_ptr* RAPTORQ_LOCAL v1_Encoder_nodata (RaptorQ_type type,
const uint16_t symbols,
const size_t symbol_size);
struct RaptorQ_ptr* RAPTORQ_LOCAL v1_Encoder (RaptorQ_type type,
const void* from, const void* to,
const size_t symbol_size);
struct RaptorQ_ptr* RAPTORQ_LOCAL v1_Decoder (RaptorQ_type type,
const uint16_t symbols,
const size_t symbol_size,
const RaptorQ_Compute report);
// common functions
static uint16_t RAPTORQ_LOCAL v1_symbols (const RaptorQ_ptr *ptr);
static size_t RAPTORQ_LOCAL v1_symbol_size (const RaptorQ_ptr *ptr);
static RaptorQ_Error RAPTORQ_LOCAL v1_future_state (struct RaptorQ_future *f);
static RaptorQ_Error RAPTORQ_LOCAL v1_future_wait_for (struct RaptorQ_future *f,
const uint64_t time,
const RaptorQ_Unit_Time unit);
static void RAPTORQ_LOCAL v1_future_wait (struct RaptorQ_future *f);
static void RAPTORQ_LOCAL v1_future_free (struct RaptorQ_future **f);
// encoder-specific
static uint32_t RAPTORQ_LOCAL v1_max_repair (const RaptorQ_ptr *enc);
static size_t RAPTORQ_LOCAL v1_add_data (const RaptorQ_ptr *enc, void *from,
const void *to);
static void RAPTORQ_LOCAL v1_clear_data (const RaptorQ_ptr *enc);
static size_t RAPTORQ_LOCAL v1_needed_bytes (const RaptorQ_ptr *enc);
static bool RAPTORQ_LOCAL v1_compute_sync (const RaptorQ_ptr *enc);
static RaptorQ_future_enc* RAPTORQ_LOCAL v1_compute (const RaptorQ_ptr *enc);
static RaptorQ_Error RAPTORQ_LOCAL v1_enc_future_get (
struct RaptorQ_future_enc *f);
static size_t RAPTORQ_LOCAL v1_encode (const RaptorQ_ptr *enc, void *from,
const void *to, const uint32_t id);
// decoder-specific
static RaptorQ_Error RAPTORQ_LOCAL v1_add_symbol (const RaptorQ_ptr *dec,
void *from,
const void *to,
const uint32_t esi);
static bool RAPTORQ_LOCAL v1_can_decode (const RaptorQ_ptr *dec);
static void RAPTORQ_LOCAL v1_stop (const RaptorQ_ptr *dec);
static uint16_t RAPTORQ_LOCAL v1_needed_symbols (const RaptorQ_ptr *dec);
static RaptorQ_dec_result RAPTORQ_LOCAL v1_poll (const RaptorQ_ptr *dec);
static RaptorQ_dec_result RAPTORQ_LOCAL v1_wait_sync (const RaptorQ_ptr *dec);
static RaptorQ_future_dec* RAPTORQ_LOCAL v1_wait (const RaptorQ_ptr *dec);
static RaptorQ_dec_result RAPTORQ_LOCAL v1_dec_future_get (
struct RaptorQ_future_dec *f);
struct RaptorQ_base_api* RAPTORQ_API RaptorQ_api (uint32_t version)
{
if (version != 1)
return nullptr;
auto api = new RaptorQ_v1();
api->base.version = 1;
// precomputation caching
api->supported_compressions = &v1_supported_compressions;
api->get_compression = &v1_get_compression;
api->set_compression = &v1_set_compression;
api->shared_cache_size = &v1_shared_cache_size;
api->local_cache_size = &v1_local_cache_size;
api->get_shared_cache_size = &v1_get_shared_cache_size;
api->get_local_cache_size = &v1_get_local_cache_size;
// constructors
api->Encoder_nodata = &v1_Encoder_nodata;
api->Encoder = &v1_Encoder;
api->Decoder = &v1_Decoder;
// common functions
api->symbols = &v1_symbols;
api->symbol_size = &v1_symbol_size;
api->future_state = &v1_future_state;
api->future_wait_for = &v1_future_wait_for;
api->future_wait = &v1_future_wait;
api->future_free = &v1_future_free;
// encoder-specific functions
api->max_repair = &v1_max_repair;
api->add_data = &v1_add_data;
api->clear_data = &v1_clear_data;
api->needed_bytes = &v1_needed_bytes;
api->compute_sync = &v1_compute_sync;
api->compute = &v1_compute;
api->enc_future_get = &v1_enc_future_get;
api->encode = &v1_encode;
// decoder-specific functions
api->add_symbol = &v1_add_symbol;
api->can_decode = &v1_can_decode;
api->stop = &v1_stop;
api->needed_symbols = &v1_needed_symbols;
api->poll = &v1_poll;
api->wait_sync = &v1_wait_sync;
api->wait = &v1_wait;
api->dec_future_get = &v1_dec_future_get;
return reinterpret_cast<RaptorQ_base_api *> (api);
}
///////////////////////////
// Precomputation caching
///////////////////////////
static RaptorQ_Compress v1_supported_compressions()
{
return static_cast<RaptorQ_Compress>(RaptorQ__v1::supported_compressions());
}
static RaptorQ_Compress v1_get_compression()
{ return static_cast<RaptorQ_Compress>(RaptorQ__v1::get_compression()); }
static bool v1_set_compression (const RaptorQ_Compress compression)
{
return static_cast<RaptorQ_Compress> (RaptorQ__v1::set_compression (
static_cast<RaptorQ__v1::Compress> (compression)));
}
static size_t v1_shared_cache_size (const size_t shared_cache)
{ return RaptorQ__v1::shared_cache_size (shared_cache); }
static size_t v1_local_cache_size (const size_t local_cache)
{ return RaptorQ__v1::local_cache_size (local_cache); }
static size_t v1_get_shared_cache_size ()
{ return RFC6330__v1::get_shared_cache_size(); }
static size_t v1_get_local_cache_size ()
{return RFC6330__v1::get_local_cache_size(); }
/////////////////////
// Constructors
/////////////////////
struct RaptorQ_ptr* RAPTORQ_LOCAL v1_Encoder_nodata (RaptorQ_type type,
const uint16_t symbols,
const size_t symbol_size)
{
std::unique_ptr<RaptorQ_ptr> ret (new RaptorQ_ptr (type));
switch (type) {
case RaptorQ_type::RQ_ENC_8:
ret->ptr = reinterpret_cast<void *> (
new RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*> (
symbols, symbol_size));
break;
case RaptorQ_type::RQ_ENC_16:
ret->ptr = reinterpret_cast<void *> (
new RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*> (
symbols, symbol_size));
break;
case RaptorQ_type::RQ_ENC_32:
ret->ptr = reinterpret_cast<void *> (
new RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*> (
symbols, symbol_size));
break;
case RaptorQ_type::RQ_ENC_64:
ret->ptr = reinterpret_cast<void *> (
new RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*> (
symbols, symbol_size));
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:
return new RaptorQ_ptr (RaptorQ_type::RQ_NONE);
}
if (ret->ptr == nullptr)
return nullptr;
return ret.release();
}
struct RaptorQ_ptr* RAPTORQ_LOCAL v1_Encoder (RaptorQ_type type,
const void* from, const void* to,
const size_t symbol_size)
{
std::unique_ptr<RaptorQ_ptr> ret (new RaptorQ_ptr (type));
switch (type) {
case RaptorQ_type::RQ_ENC_8:
ret->ptr = reinterpret_cast<void *> (
new RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*> (
reinterpret_cast<uint8_t*>(const_cast<void*>(from)),
reinterpret_cast<uint8_t*>(const_cast<void*>(to)),
symbol_size));
break;
case RaptorQ_type::RQ_ENC_16:
ret->ptr = reinterpret_cast<void *> (
new RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*> (
reinterpret_cast<uint16_t*>(const_cast<void*>(from)),
reinterpret_cast<uint16_t*>(const_cast<void*>(to)),
symbol_size));
break;
case RaptorQ_type::RQ_ENC_32:
ret->ptr = reinterpret_cast<void *> (
new RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*> (
reinterpret_cast<uint32_t*>(const_cast<void*>(from)),
reinterpret_cast<uint32_t*>(const_cast<void*>(to)),
symbol_size));
break;
case RaptorQ_type::RQ_ENC_64:
ret->ptr = reinterpret_cast<void *> (
new RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*> (
reinterpret_cast<uint64_t*>(const_cast<void*>(from)),
reinterpret_cast<uint64_t*>(const_cast<void*>(to)),
symbol_size));
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:
return new RaptorQ_ptr (RaptorQ_type::RQ_NONE);
}
if (ret->ptr == nullptr)
return nullptr;
return ret.release();
}
struct RaptorQ_ptr* RAPTORQ_LOCAL v1_Decoder (RaptorQ_type type,
const uint16_t symbols,
const size_t symbol_size,
const RaptorQ_Compute report)
{
if (report != RQ_COMPUTE_PARTIAL_FROM_BEGINNING &&
report != RQ_COMPUTE_PARTIAL_ANY &&
report != RQ_COMPUTE_COMPLETE) {
return nullptr;
}
std::unique_ptr<RaptorQ_ptr> ret (new RaptorQ_ptr (type));
namespace RQ = RaptorQ__v1::Impl;
switch (type) {
case RaptorQ_type::RQ_DEC_8:
ret->ptr = reinterpret_cast<void *> (
new RQ::Decoder<uint8_t*, uint8_t*> (symbols, symbol_size,
static_cast<RQ::Decoder<uint8_t*, uint8_t*>::Report> (report)));
break;
case RaptorQ_type::RQ_DEC_16:
ret->ptr = reinterpret_cast<void *> (
new RQ::Decoder<uint16_t*, uint16_t*> (symbols, symbol_size,
static_cast<RQ::Decoder<uint16_t*, uint16_t*>::Report> (report)));
break;
case RaptorQ_type::RQ_DEC_32:
ret->ptr = reinterpret_cast<void *> (
new RQ::Decoder<uint32_t*, uint32_t*> (symbols, symbol_size,
static_cast<RQ::Decoder<uint32_t*, uint32_t*>::Report> (report)));
break;
case RaptorQ_type::RQ_DEC_64:
ret->ptr = reinterpret_cast<void *> (
new RQ::Decoder<uint64_t*, uint64_t*> (symbols, symbol_size,
static_cast<RQ::Decoder<uint64_t*, uint64_t*>::Report> (report)));
break;
case RaptorQ_type::RQ_ENC_8:
case RaptorQ_type::RQ_ENC_16:
case RaptorQ_type::RQ_ENC_32:
case RaptorQ_type::RQ_ENC_64:
case RaptorQ_type::RQ_NONE:
return new RaptorQ_ptr (RaptorQ_type::RQ_NONE);
}
if (ret->ptr == nullptr)
return nullptr;
return ret.release();
}
/////////////////////
// Common functions
/////////////////////
static uint16_t v1_symbols (const RaptorQ_ptr *ptr)
{
if (ptr == nullptr || ptr->ptr == nullptr)
return 0;
switch (ptr->type) {
case RaptorQ_type::RQ_ENC_8:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->symbols();
case RaptorQ_type::RQ_ENC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->symbols();
case RaptorQ_type::RQ_ENC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->symbols();
case RaptorQ_type::RQ_ENC_64:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->symbols();
case RaptorQ_type::RQ_DEC_8:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->symbols();
case RaptorQ_type::RQ_DEC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->symbols();
case RaptorQ_type::RQ_DEC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->symbols();
case RaptorQ_type::RQ_DEC_64:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->symbols();
case RaptorQ_type::RQ_NONE:
break;
}
return 0;
}
static size_t v1_symbol_size (const RaptorQ_ptr *ptr)
{
if (ptr == nullptr || ptr->ptr == nullptr)
return 0;
switch (ptr->type) {
case RaptorQ_type::RQ_ENC_8:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::RQ_ENC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::RQ_ENC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::RQ_ENC_64:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::RQ_DEC_8:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::RQ_DEC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::RQ_DEC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::RQ_DEC_64:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::RQ_NONE:
break;
}
return 0;
}
static RaptorQ_Error v1_future_state (struct RaptorQ_future *f)
{
if (f == nullptr)
return RaptorQ_Error::RQ_ERR_WRONG_INPUT;
switch (f->type)
{
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
if (reinterpret_cast<RaptorQ_future_enc*> (f)->f.valid())
return RaptorQ_Error::RQ_ERR_NONE;
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
if (reinterpret_cast<RaptorQ_future_dec*> (f)->f.valid())
return RaptorQ_Error::RQ_ERR_NONE;
}
return RaptorQ_Error::RQ_ERR_WORKING;
}
static RaptorQ_Error v1_future_wait_for (struct RaptorQ_future *f,
const uint64_t time,
const RaptorQ_Unit_Time unit)
{
if (f == nullptr)
return RQ_ERR_WRONG_INPUT;
std::future_status status = std::future_status::timeout;
switch (unit) {
case RQ_TIME_NANOSEC:
switch (f->type)
{
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
status = reinterpret_cast<RaptorQ_future_enc*>(f)->f.wait_for (
std::chrono::nanoseconds (time));
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
status = reinterpret_cast<RaptorQ_future_dec*>(f)->f.wait_for (
std::chrono::nanoseconds (time));
}
break;
case RQ_TIME_MICROSEC:
switch (f->type)
{
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
status = reinterpret_cast<RaptorQ_future_enc*>(f)->f.wait_for (
std::chrono::microseconds (time));
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
status = reinterpret_cast<RaptorQ_future_dec*>(f)->f.wait_for (
std::chrono::microseconds (time));
}
break;
case RQ_TIME_MILLISEC:
switch (f->type)
{
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
status = reinterpret_cast<RaptorQ_future_enc*>(f)->f.wait_for (
std::chrono::milliseconds (time));
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
status = reinterpret_cast<RaptorQ_future_dec*>(f)->f.wait_for (
std::chrono::milliseconds (time));
}
break;
case RQ_TIME_SEC:
switch (f->type)
{
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
status = reinterpret_cast<RaptorQ_future_enc*>(f)->f.wait_for (
std::chrono::seconds (time));
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
status = reinterpret_cast<RaptorQ_future_dec*>(f)->f.wait_for (
std::chrono::seconds (time));
}
break;
case RQ_TIME_MIN:
switch (f->type)
{
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
status = reinterpret_cast<RaptorQ_future_enc*>(f)->f.wait_for (
std::chrono::minutes (time));
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
status = reinterpret_cast<RaptorQ_future_dec*>(f)->f.wait_for (
std::chrono::minutes (time));
}
break;
case RQ_TIME_HOUR:
switch (f->type)
{
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
status = reinterpret_cast<RaptorQ_future_enc*>(f)->f.wait_for (
std::chrono::hours (time));
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
status = reinterpret_cast<RaptorQ_future_dec*>(f)->f.wait_for (
std::chrono::hours (time));
}
break;
}
if (status == std::future_status::ready)
return RaptorQ_Error::RQ_ERR_NONE;
return RaptorQ_Error::RQ_ERR_WORKING;
}
static void v1_future_wait (struct RaptorQ_future *f)
{
if (f == nullptr)
return;
switch (f->type)
{
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
reinterpret_cast<RaptorQ_future_enc*>(f)->f.wait();
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
reinterpret_cast<RaptorQ_future_dec*>(f)->f.wait();
}
}
static void v1_future_free (struct RaptorQ_future **f)
{
if (f == nullptr || *f == nullptr)
return;
switch ((*f)->type) {
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
delete reinterpret_cast<RaptorQ_future_enc*>(*f);
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
delete reinterpret_cast<RaptorQ_future_dec*>(*f);
}
*f = nullptr;
}
//////////////////////////////
// Encoder-specific functions
//////////////////////////////
static uint32_t v1_max_repair (const RaptorQ_ptr *enc)
{
if (enc == nullptr || enc->ptr == nullptr)
return 0;
switch (enc->type) {
case RaptorQ_type::RQ_ENC_8:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr))->max_repair();
case RaptorQ_type::RQ_ENC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr))->max_repair();
case RaptorQ_type::RQ_ENC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr))->max_repair();
case RaptorQ_type::RQ_ENC_64:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr))->max_repair();
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;
}
static size_t v1_add_data (const RaptorQ_ptr *enc, void *from, const void *to)
{
if (enc == nullptr || enc->ptr == nullptr)
return 0;
uint8_t *f_8 = reinterpret_cast<uint8_t*> (from);
uint16_t *f_16 = reinterpret_cast<uint16_t*> (from);
uint32_t *f_32 = reinterpret_cast<uint32_t*> (from);
uint64_t *f_64= reinterpret_cast<uint64_t*> (from);
size_t ret;
switch (enc->type) {
case RaptorQ_type::RQ_ENC_8:
ret = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr)->add_data (f_8,
reinterpret_cast<uint8_t*> (
const_cast<void*>(to)));
from = reinterpret_cast<void*> (f_8);
return ret;
case RaptorQ_type::RQ_ENC_16:
ret = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr)->add_data (f_16,
reinterpret_cast<uint16_t*>(
const_cast<void*>(to)));
from = reinterpret_cast<void*> (f_16);
return ret;
case RaptorQ_type::RQ_ENC_32:
ret = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr)->add_data (f_32,
reinterpret_cast<uint32_t*>(
const_cast<void*>(to)));
from = reinterpret_cast<void*> (f_32);
return ret;
case RaptorQ_type::RQ_ENC_64:
ret = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr)->add_data (f_64,
reinterpret_cast<uint64_t*>(
const_cast<void*>(to)));
from = reinterpret_cast<void*> (f_64);
return ret;
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;
}
static void v1_clear_data (const RaptorQ_ptr *enc)
{
if (enc == nullptr || enc->ptr == nullptr)
return;
switch (enc->type) {
case RaptorQ_type::RQ_ENC_8:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr))->clear_data();
case RaptorQ_type::RQ_ENC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr))->clear_data();
case RaptorQ_type::RQ_ENC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr))->clear_data();
case RaptorQ_type::RQ_ENC_64:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr))->clear_data();
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:
return;
}
}
static size_t v1_needed_bytes (const RaptorQ_ptr *enc)
{
if (enc == nullptr || enc->ptr == nullptr)
return 0;
switch (enc->type) {
case RaptorQ_type::RQ_ENC_8:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr))->needed_bytes();
case RaptorQ_type::RQ_ENC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr))->needed_bytes();
case RaptorQ_type::RQ_ENC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr))->needed_bytes();
case RaptorQ_type::RQ_ENC_64:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr))->needed_bytes();
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;
}
static bool v1_compute_sync (const RaptorQ_ptr *enc)
{
if (enc == nullptr || enc->ptr == nullptr)
return false;
switch (enc->type) {
case RaptorQ_type::RQ_ENC_8:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr))->compute_sync();
case RaptorQ_type::RQ_ENC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr))->compute_sync();
case RaptorQ_type::RQ_ENC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr))->compute_sync();
case RaptorQ_type::RQ_ENC_64:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr))->compute_sync();
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;
}
static RaptorQ_future_enc* v1_compute (const RaptorQ_ptr *enc)
{
if (enc == nullptr || enc->ptr == nullptr)
return nullptr;
RaptorQ_future_enc *fut = new RaptorQ_future_enc();
switch (enc->type) {
case RaptorQ_type::RQ_ENC_8:
fut->f = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr)->compute();
break;
case RaptorQ_type::RQ_ENC_16:
fut->f = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr)->compute();
break;
case RaptorQ_type::RQ_ENC_32:
fut->f = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr)->compute();
break;
case RaptorQ_type::RQ_ENC_64:
fut->f = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr)->compute();
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:
return nullptr;
}
return fut;
}
static RaptorQ_Error v1_enc_future_get (struct RaptorQ_future_enc *f)
{
if (f == nullptr)
return RaptorQ_Error::RQ_ERR_WRONG_INPUT;
if (f->f.valid())
return static_cast<RaptorQ_Error> (f->f.get());
return RaptorQ_Error::RQ_ERR_WORKING;
}
static size_t v1_encode (const RaptorQ_ptr *enc, void *from, const void *to,
const uint32_t id)
{
if (enc == nullptr || enc->ptr == nullptr)
return 0;
uint8_t *f_8 = reinterpret_cast<uint8_t*> (from);
uint16_t *f_16 = reinterpret_cast<uint16_t*> (from);
uint32_t *f_32 = reinterpret_cast<uint32_t*> (from);
uint64_t *f_64= reinterpret_cast<uint64_t*> (from);
size_t ret;
switch (enc->type) {
case RaptorQ_type::RQ_ENC_8:
ret = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr)->encode (f_8,
reinterpret_cast<uint8_t*> (
const_cast<void*>(to)), id);
from = reinterpret_cast<void*> (f_8);
return ret;
case RaptorQ_type::RQ_ENC_16:
ret = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr)->encode (f_16,
reinterpret_cast<uint16_t*>(
const_cast<void*>(to)), id);
from = reinterpret_cast<void*> (f_16);
return ret;
case RaptorQ_type::RQ_ENC_32:
ret = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr)->encode (f_32,
reinterpret_cast<uint32_t*>(
const_cast<void*>(to)), id);
from = reinterpret_cast<void*> (f_32);
return ret;
case RaptorQ_type::RQ_ENC_64:
ret = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr)->encode (f_64,
reinterpret_cast<uint64_t*>(
const_cast<void*>(to)), id);
from = reinterpret_cast<void*> (f_64);
return ret;
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;
}
//////////////////////////////
// Decoder-specific functions
//////////////////////////////
static RaptorQ_Error v1_add_symbol (const RaptorQ_ptr *dec, void *from,
const void *to,
const uint32_t esi)
{
if (dec == nullptr || dec->ptr == nullptr)
return RaptorQ_Error::RQ_ERR_WRONG_INPUT;
uint8_t *f_8 = reinterpret_cast<uint8_t*> (from);
uint16_t *f_16 = reinterpret_cast<uint16_t*> (from);
uint32_t *f_32 = reinterpret_cast<uint32_t*> (from);
uint64_t *f_64= reinterpret_cast<uint64_t*> (from);
switch (dec->type) {
case RaptorQ_type::RQ_DEC_8:
return static_cast<RaptorQ_Error> (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint8_t*, uint8_t*>*> (
dec->ptr)->add_symbol (f_8,
reinterpret_cast<uint8_t*> (
const_cast<void*>(to)), esi));
case RaptorQ_type::RQ_DEC_16:
return static_cast<RaptorQ_Error> (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint16_t*, uint16_t*>*> (
dec->ptr)->add_symbol (f_16,
reinterpret_cast<uint16_t*>(
const_cast<void*>(to)), esi));
case RaptorQ_type::RQ_DEC_32:
return static_cast<RaptorQ_Error> (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint32_t*, uint32_t*>*> (
dec->ptr)->add_symbol (f_32,
reinterpret_cast<uint32_t*>(
const_cast<void*>(to)), esi));
case RaptorQ_type::RQ_DEC_64:
return static_cast<RaptorQ_Error> (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint64_t*, uint64_t*>*> (
dec->ptr)->add_symbol (f_64,
reinterpret_cast<uint64_t*>(
const_cast<void*>(to)), esi));
case RaptorQ_type::RQ_ENC_8:
case RaptorQ_type::RQ_ENC_16:
case RaptorQ_type::RQ_ENC_32:
case RaptorQ_type::RQ_ENC_64:
case RaptorQ_type::RQ_NONE:
break;
}
return RaptorQ_Error::RQ_ERR_WRONG_INPUT;
}
static bool v1_can_decode (const RaptorQ_ptr *dec)
{
if (dec == nullptr || dec->ptr == nullptr)
return false;
switch (dec->type) {
case RaptorQ_type::RQ_DEC_8:
return reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint8_t*, uint8_t*>*> (
dec->ptr)->can_decode();
case RaptorQ_type::RQ_DEC_16:
return reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint16_t*, uint16_t*>*> (
dec->ptr)->can_decode();
case RaptorQ_type::RQ_DEC_32:
return reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint32_t*, uint32_t*>*> (
dec->ptr)->can_decode();
case RaptorQ_type::RQ_DEC_64:
return reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint64_t*, uint64_t*>*> (
dec->ptr)->can_decode();
case RaptorQ_type::RQ_ENC_8:
case RaptorQ_type::RQ_ENC_16:
case RaptorQ_type::RQ_ENC_32:
case RaptorQ_type::RQ_ENC_64:
case RaptorQ_type::RQ_NONE:
break;
}
return false;
}
static void v1_stop (const RaptorQ_ptr *dec)
{
if (dec == nullptr || dec->ptr == nullptr)
return;
switch (dec->type) {
case RaptorQ_type::RQ_DEC_8:
return reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint8_t*, uint8_t*>*> (
dec->ptr)->stop();
case RaptorQ_type::RQ_DEC_16:
return reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint16_t*, uint16_t*>*> (
dec->ptr)->stop();
case RaptorQ_type::RQ_DEC_32:
return reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint32_t*, uint32_t*>*> (
dec->ptr)->stop();
case RaptorQ_type::RQ_DEC_64:
return reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint64_t*, uint64_t*>*> (
dec->ptr)->stop();
case RaptorQ_type::RQ_ENC_8:
case RaptorQ_type::RQ_ENC_16:
case RaptorQ_type::RQ_ENC_32:
case RaptorQ_type::RQ_ENC_64:
case RaptorQ_type::RQ_NONE:
return;
}
}
static uint16_t v1_needed_symbols (const RaptorQ_ptr *dec)
{
if (dec == nullptr || dec->ptr == nullptr)
return false;
switch (dec->type) {
case RaptorQ_type::RQ_DEC_8:
return reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint8_t*, uint8_t*>*> (
dec->ptr)->needed_symbols();
case RaptorQ_type::RQ_DEC_16:
return reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint16_t*, uint16_t*>*> (
dec->ptr)->needed_symbols();
case RaptorQ_type::RQ_DEC_32:
return reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint32_t*, uint32_t*>*> (
dec->ptr)->needed_symbols();
case RaptorQ_type::RQ_DEC_64:
return reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint64_t*, uint64_t*>*> (
dec->ptr)->needed_symbols();
case RaptorQ_type::RQ_ENC_8:
case RaptorQ_type::RQ_ENC_16:
case RaptorQ_type::RQ_ENC_32:
case RaptorQ_type::RQ_ENC_64:
case RaptorQ_type::RQ_NONE:
break;
}
return 0;
}
static RaptorQ_dec_result v1_poll (const RaptorQ_ptr *dec)
{
RaptorQ_dec_result res;
res.err = RaptorQ_Error::RQ_ERR_WRONG_INPUT;
res.esi = 0;
if (dec == nullptr || dec->ptr == nullptr)
return res;
std::pair<RaptorQ__v1::Error, uint16_t> cpp_res = {
RaptorQ__v1::Error::WRONG_INPUT, 0};
switch (dec->type) {
case RaptorQ_type::RQ_DEC_8:
cpp_res = reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint8_t*, uint8_t*>*> (
dec->ptr)->poll();
break;
case RaptorQ_type::RQ_DEC_16:
cpp_res = reinterpret_cast<