Issue #868 encoder mutating the shared message

Add copy on write semantics to the encoder write_message API