Skip to content

Instantly share code, notes, and snippets.

@mic159
Created June 5, 2017 13:23
Show Gist options
  • Save mic159/0c37f8c35d309933e73d60f30a741c20 to your computer and use it in GitHub Desktop.
Save mic159/0c37f8c35d309933e73d60f30a741c20 to your computer and use it in GitHub Desktop.
python zfec usage
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