Move protocol encoding into a separate modules