compiler: use writeMessageBegin/writeMessageEnd properly