Repository navigation
feat(common-avro,common-json,common-protobuf): reach the metadata envelope from a format-native stage - #2394
Merged
Merged
Conversation
…at-native stage An AvroStream pipeline could carry no metadata alongside the datum it transforms, so a stage working over the format's own event stream had no place to read or write data that is not part of the datum's encoding. The engine's own metadata channel could not fill the gap either: common-avro does not depend on engine and so cannot name it. Add AvroEnvelope, common-avro's own named, ordered, repeatable list of byte values, with the same accumulating set as any such channel: a repeated call under one name adds a further occurrence rather than overwriting the one before it, get returns null for an absent name or an index past the end, and the bytes are copied out before set returns. It is bound to a pipeline once, through AvroStream.envelope(...), and read back by any stage through AvroController.envelope(). The default is AvroEnvelope.NONE, which reads as empty and discards writes, so a pipeline assembled without one costs a stage that never asks for it nothing. model-avro adapts the two vocabularies: AvroModelEnvelope forwards each call to the ModelEnvelope the caller supplied at supplyDecoder/supplyEncoder time, and resolves to AvroEnvelope.NONE when the caller supplied ModelEnvelope.NONE, so no wrapper exists on the path that carries nothing. The adaptation happens once, as the pipeline is assembled, leaving the hot path unchanged. Coverage in common-avro for the envelope's own contract, NONE in force when a pipeline is assembled without one, and a stage reading and writing it through its controller; in model-avro for an extension's format-native stage reading a name the caller supplied on decode, writing one on encode for the caller to drain, one envelope observed identically by a format-native stage and a ModelTransform, and NONE reaching a stage when the caller supplies none. Claude-Session: https://claude.ai/code/session_01MZhZD2wyJbgzXrFMbWYY3y Co-authored-by: Claude <[email protected]>
…e metadata envelope from a format-native stage Mirrors the avro pair: neither a JsonStream nor a ProtobufStream pipeline could carry metadata alongside the value it transforms, so a stage working over either format's own event stream had no place to read or write data that is not part of the value's encoding, and neither common module can name the engine's own channel. Add JsonEnvelope and ProtobufEnvelope, each its own named, ordered, repeatable list of byte values with the same accumulating set, bound to a pipeline once through JsonStream.envelope(...) / ProtobufStream.envelope(...) and read back by any stage through the format's own controller. Both default to NONE, which reads as empty and discards writes. model-json and model-protobuf each adapt their format's envelope to the ModelEnvelope the caller supplied at supplyDecoder/supplyEncoder time, resolving to the format's own NONE when the caller supplied ModelEnvelope.NONE, so nothing wraps a channel that carries nothing. The adaptation happens once, as the pipeline is assembled. Coverage in each model module mirrors the avro pair: an extension's format-native stage reading a name the caller supplied on decode, writing one on encode for the caller to drain, one envelope observed identically by a format-native stage and a ModelTransform, and NONE reaching a stage when the caller supplies none. Claude-Session: https://claude.ai/code/session_01MZhZD2wyJbgzXrFMbWYY3y Co-authored-by: Claude <[email protected]>
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.
Description
A stage working over a format's own event stream had no place to read or write data that travels with a value but is not part of its encoding. The engine's metadata channel could not fill the gap either:
common-avro,common-json, andcommon-protobufdo not depend onengine, so none of them can nameModelEnvelope.Each format layer gains its own channel, and each model module adapts.
AvroEnvelope/JsonEnvelope/ProtobufEnvelope— a named, ordered, repeatable list of byte values per format, all three with the same contract:setaccumulates so a repeated call under one name adds a further occurrence rather than overwriting the one before it,getreturnsnullfor an absent name or an index past the end, and the bytes are copied out beforesetreturns. Scope is the supplier's to decide; the interface claims only thread confinement, being a property of the pipeline it is bound to.Bound to a pipeline once, as it is assembled:
and read back from any stage through the format's own controller —
AvroController.envelope(),JsonController.envelope(),ProtobufController.envelope()— each defaulting to that format'sNONE, which reads as empty and discards writes. A pipeline assembled without one costs a stage that never asks for it nothing.AvroModelEnvelope/JsonModelEnvelope/ProtobufModelEnvelopebridge the two vocabularies, forwarding each call to theModelEnvelopethe caller supplied atsupplyDecoder/supplyEncodertime. Each resolves to its format's ownNONEwhen the caller suppliedModelEnvelope.NONE, so nothing wraps a channel that carries nothing. The adaptation happens once, as the pipeline is assembled, leaving the hot path unchanged — no per-value or per-call adaptation.Both directions: decode and encode chains each bind the envelope, so a stage appended to either reaches it on the same terms.
Scope
Implements #2389 §3 (per-format interface, the alternative chosen over a shared home), §4, and §5 for the three
common-*/model-*pairs.§2 asked for per-message supply. That is answered rather than built: #2390 binds the envelope at supply time and makes the supplier responsible for turning its contents over, so the pipeline never receives an envelope belonging to a different message by construction. The issue description is amended to match.
model-coreis not covered here. Its extension stages take one fully-buffered value with no control handle to reach an envelope through, and its extension handler declares no direction at all — reshaping that contract is #2393, and the envelope for those two models follows from it.Coverage
AvroEnvelopeTestincommon-avrocovers the contract itself,NONEin force when a pipeline is assembled without one, and a stage reading and writing through its controller.AvroModelEnvelopeTest,JsonModelEnvelopeTest, andProtobufModelEnvelopeTesteach cover an extension's format-native stage reading a name the caller supplied on decode, writing one on encode for the caller to drain, one envelope observed identically by a format-native stage and aModelTransform, andNONEreaching a stage when the caller supplies none.Verified with
./mvnw clean install— integration tests included — overcommon-avro,common-json,common-protobuf,model-avro,model-json, andmodel-protobuf: BUILD SUCCESS, checkstyle and JaCoCo clean across all six.Fixes #2389
Generated by Claude Code