protocol.py restructuring and improvements for future changes

Felt obligated to clean up some of the mess I've been involved in.

The primary reason of this pull request is to improve the codebase we have for future changes.

It is divided into three parts.

* externalized packing from protocol
* cleaned up lambda mess with field types
* fixed some protocol.py indentation, whitespace and commenting issues

Each of them has a longer description, feel free to reference them directly.