Created
June 5, 2017 13:23
-
-
Save mic159/0c37f8c35d309933e73d60f30a741c20 to your computer and use it in GitHub Desktop.
python zfec usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from zfec.easyfec import Encoder, Decoder | |
import random | |
# 5 correction blocks for every 20 blocks | |
enc = Encoder(20, 25) | |
dec = Decoder(20, 25) | |
# Dummy payload | |
data = ' '.join(str(x) for x in range(100)) | |
stream = enc.encode(data) | |
# Attach block numbers and pick a random 20 | |
packets = random.sample(enumerate(stream), 20) | |
for i, d in packets: | |
print i, d | |
# now pass in the blocks + blocknums | |
blocks = list(x[1] for x in packets) | |
blocknums = list(x[0] for x in packets) | |
decoded = dec.decode(blocks, sharenums=blocknums, padlen=0) | |
print decoded |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment