Move invocation argument encoding out to a separate function