Skip to content

Instantly share code, notes, and snippets.

@Dav1dde
Created June 14, 2012 21:02
Show Gist options
  • Save Dav1dde/2932930 to your computer and use it in GitHub Desktop.
Save Dav1dde/2932930 to your computer and use it in GitHub Desktop.
def output_plain(buf):
sizes = [28, 24, 20, 16, 12, 8, 4, 3, 2, 1]
while len(buf):
for size in sizes:
if size <= len(buf):
data = buf[:size]
if size < 4:
yield pack('<B', 0xfc + len(data)) + data
else:
yield pack('<B', 0xe0 | ((len(data) - 4) >> 2)) + data
buf = buf[size:]
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment