RDB merge and test

Mostly RDB stuff -- let the writer be in charge of final formatting (header comment chars, type info line, and line endings).

Plus tests.