Skip to content

Instantly share code, notes, and snippets.

@BMU-Verlag
Created January 23, 2020 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BMU-Verlag/abf13ea6784a4ed7d1759f495854428a to your computer and use it in GitHub Desktop.
Save BMU-Verlag/abf13ea6784a4ed7d1759f495854428a to your computer and use it in GitHub Desktop.
LENGTH_HEADER_SIZE = 8
USER_HEADER_SIZE = 16
def format_message(username, message):
if not message:
return None
length_header = f'{len(message):<{LENGTH_HEADER_SIZE}}'
user_header = f'{username:<{USER_HEADER_SIZE}}'
return f'{length_header}{user_header}{message}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment