Move proto encoding to handler