cpp runtime: Remove extraneous copies from codec and listener