SIGN IN SIGN UP

Protocol Buffers - Google's data interchange format

0 0 19 C++

fix(cpp): stop TextFormat iteration if output stream fails (#26237)

The TextFormat::Printer currently continues to iterate over fields and repeated elements even after the underlying ZeroCopyOutputStream returns false. This results in unnecessary CPU usage (reflection and formatting) for large messages.

This change:
- Adds a virtual failed() method to BaseTextGenerator.
- Implements failed() in the concrete TextFormat::Printer::TextGenerator to expose the state of the output stream.
- Adds short-circuit checks to exit early if the generator has failed (TextFormat::Printer::PrintMessage, TextFormat::Printer::PrintField, TextFormat::Printer::PrintShortRepeatedField)

Fixes: #23288

Closes #26237

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/26237 from jschroedr:bugfix/#23288 811d0579c6beb4d01730a8e94e659c7ff632b766
PiperOrigin-RevId: 917325569
J
jschroedr committed
2718dd5f3dda891f7e0224e5f50aa946219499ff
Parent: 92dd27c
Committed by Copybara-Service <copybara-worker@google.com> on 5/18/2026, 6:04:33 PM