Skip to content

Add opt-in protobuf TextFormat serialization and deserialization#4

Merged
merlimat merged 1 commit intostreamnative:masterfrom
merlimat:add-textformat-support
May 7, 2026
Merged

Add opt-in protobuf TextFormat serialization and deserialization#4
merlimat merged 1 commit intostreamnative:masterfrom
merlimat:add-textformat-support

Conversation

@merlimat
Copy link
Copy Markdown
Collaborator

@merlimat merlimat commented May 7, 2026

Summary

  • Adds an opt-in generateTextFormat option to the Maven and Gradle plugins. When enabled, every generated message gets toTextFormat() / writeTextFormatTo(StringBuilder) / parseFromTextFormat(String|byte[]|ByteBuf) methods. Default off.
  • Output is protobuf canonical multi-line, indented TextFormat — compatible with com.google.protobuf.TextFormat.printer() for serialization and TextFormat.merge() for parsing, so existing TextFormat data round-trips.
  • Cross-package sub-messages work by sharing a ByteBuf as the parser cursor (the same handoff trick used by the JSON reader), so a message that references a type from a different generated package parses correctly.

Format details — TextFormat differs from JSON: field names are the original proto snake_case (not lowerCamelCase), int64 values are unquoted, enums are bare identifiers, bytes use C-style escapes (not base64). The parser tolerates # … comments, single- or double-quoted strings, angle-bracket sub-messages (field <…>), [v1, v2] array syntax for repeated fields, and ignores unknown fields.

Test plan

  • 15 new round-trip tests in TextFormatTest covering: scalars, strings (with escapes + UTF-8), nested messages, repeated, maps, bytes, empty messages, nan / inf, angle-bracket sub-messages, # comments, unknown-field skipping, cross-package message references, plus invariants (enum unquoted, int64 unquoted, snake_case field names).
  • All 258 tests pass (243 pre-existing + 15 new), both with default JVM flags and with -XX:-CompactStrings.
  • tests/pom.xml enables generateTextFormat=true so the existing proto files exercise the new code paths.

@merlimat merlimat merged commit 2382556 into streamnative:master May 7, 2026
1 check passed
@merlimat merlimat deleted the add-textformat-support branch May 7, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant