Implement encode for rpc responses