Guard MessagePack with a ThreadLocal where necessary

Unfortunately MessagePack (or more precisely the TemplateRegistry and BuildContext)
is not thread-safe, so each thread will need its own instance of MessagePack to
work correctly.