rewrite to binary protocol