interface to deal with fixed erasures
Sec42 opened this issue · 1 comments
This is more a feature request. I have a RS encoding that is a bit strange. It uses 8 bytes of error correction, but instead of the expected encoding:
rs8a=reedsolo.RSCodec(nsym=8, fcr=0, prim=0x11d, c_exp=8)
it instead encodes for 16 bytes, but omits the last 8 bytes from the message.
Due to the way that reed-solomon can deal with known erasures it has the same correcting capabilities as the "standard" one.
I have written a small helper function to deal with this case:
# data: 31B, checksum: 8B, erasure: 8B - RS(47,31) - transmission omits last 8B
rs8=reedsolo.RSCodec(nsym=(8+8), fcr=0, prim=0x11d, c_exp=8)
rs8.elen=8
def decode_with_fixed_erasure(self, data, nsym=None, erase_pos=None, only_erasures=False):
if nsym is None: nsym=self.nsym
if self.elen > 0:
data=data+([0]*self.elen)
r=range(len(data)-self.elen,len(data))
if erase_pos is None:
erase_pos=r
else:
erase_pos=list(set(r)|set(erase_pos))
(cmsg,crs,ep)=self.decode(data, nsym, erase_pos=erase_pos, only_erasures=only_erasures)
return (cmsg, crs, bytearray(set(ep)-set(r)))
else:
return self.decode(data, nsym, erase_pos, only_erasures)
I wonder if this is something you would consider adding support for.
Thank you for your suggestion and for sharing your code. I won't be the one implementing it, but I leave your issue open if someone else want to give it a try or has similar needs.