make msgwriter.go more generic