45 lines
631 B
C
Raw Normal View History

2017-09-14 07:01:39 -05:00
/*
* rs.c
*
* Created on: Sep 14, 2017
* Author: root
*/
#include "rs.h"
2017-09-14 07:01:39 -05:00
2017-09-14 12:00:52 -05:00
void rs_encode(void *code,char *data[],int size)
{
int k=get_k(code);
int n=get_n(code);
for(int i=k;i<n;i++)
{
2017-09-14 12:00:52 -05:00
fec_encode(code, (void **)data, data[i],i, size);
}
2017-09-14 07:01:39 -05:00
return ;
}
2017-09-14 12:00:52 -05:00
int rs_decode(void *code,char *data[],int size)
{
int k=get_k(code);
int n=get_n(code);
int index[n];
int count=0;
for(int i=0;i<n;i++)
{
if(data[i]!=0)
{
index[count++]=i;
}
}
if(count<k)
return -1;
for(int i=0;i<n;i++)
{
2017-09-14 12:02:48 -05:00
if(i<count)
data[i]=data[index[i]];
else
data[i]=0;
}
2017-09-14 12:00:52 -05:00
return fec_decode(code,(void**)data,index,size);
}