[WIP] Refactor toCBuffer into a visitor

Because it's a mess, and names like `toCBuffer`/`toCBuffer2`/`toCBuffer3` don't help.