=rem #16428 optimize protobuf serializer for master

#16428 for master
I find it harder to read two levels of tailrec, but I'm biased, so I leave it to others to judge