Minimize number of calls to buf:write() in table serializer