Make message decoding in ProtobufDecoder more extensible - #37283
Open
AbhishekLaddha54 wants to merge 1 commit into
Open
AbhishekLaddha54 wants to merge 1 commit into
AbhishekLaddha54 wants to merge 1 commit into
Conversation
AbhishekLaddha54
force-pushed
the
gh-37265-protobuf-decoder-extensible
branch
2 times, most recently
from
September 16, 2026 12:26
2a6cccc to
233ebe9
Compare
Previously, the Flux decoding path in ProtobufDecoder hard-coded message creation via getMessageBuilder().mergeFrom().build() inside a private inner class, with a private ExtensionRegistry. This made it impossible to support gRPC-Web framing (5-byte header with trailer flag 0x80) without copying the entire class. This commit adds a protected extension point similar to the existing MessageSizeReader: - Add protected getExtensionRegistry() accessor - Add protected decodeMessage(CodedInputStream, ResolvableType) and decodeMessage(CodedInputStream, Class) returning @nullable to allow skipping trailer frames - Refactor decode(DataBuffer) and MessageDecoderFunction to delegate to decodeMessage() - Make MessageDecoderFunction protected and add createMessageDecoderFunction() factory for full override - Add getters for elementType and messageSizeReader This enables spring-grpc to implement gRPC-Web support by overriding initMessageSizeReader() to parse the 5-byte header and decodeMessage() to skip trailers, as requested in spring-projects/spring-grpc#427. Closes spring-projectsgh-37265 Signed-off-by: Abhishek <laddhaabhishek112@gmail.com>
AbhishekLaddha54
force-pushed
the
gh-37265-protobuf-decoder-extensible
branch
from
September 16, 2026 12:39
233ebe9 to
3b83c41
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes gh-37265
Summary
ProtobufDecoderrecently gained extensibility for size reading viaMessageSizeReader(7.0), but message creation is still hard-coded in a private inner class. This makes gRPC-Web support impossible without copy-paste.gRPC-Web uses:
Changes
protected ExtensionRegistry getExtensionRegistry()protected @Nullable Message decodeMessage(CodedInputStream, ResolvableType)and overload forClass<?>— returning null skips framedecode(DataBuffer, ...)andMessageDecoderFunctionto usedecodeMessage()MessageDecoderFunctionprotected with getters and addcreateMessageDecoderFunction()factoryThis mirrors the existing
initMessageSizeReader()pattern.Enables (example)
See spring-projects/spring-grpc#427
Testing
./gradlew :spring-web:test --tests "ProtobufDecoderTests" → BUILD SUCCESSFUL, 0 failures
Existing tests unchanged, new hook returns same as old logic by default
text