optimize protocol encoding