Fix encoding race condition in map data attachment.

Concurrent serialization threads can be encoding an object.
Use temporary arrays to construct the serialized format and
then publish the temporary arrays.