feat(xtcp): stdout destination + envelope JSON/text marshallers#35
Open
randomizedcoder wants to merge 1 commit into
Open
feat(xtcp): stdout destination + envelope JSON/text marshallers#35randomizedcoder wants to merge 1 commit into
randomizedcoder wants to merge 1 commit into
Conversation
Add a `stdout` destination so the daemon can print socket data to its own stdout — e.g. `xtcp2 -dest stdout -marshal protoJson` streams one JSON Envelope per poll as NDJSON, ideal for local dev, debugging, and piping to jq. The destination is backed by a reusable, io.Writer-based `writerDest` (default os.Stdout) rather than copying the null/udp boilerplate; the io.Writer seam also makes it unit-testable with a bytes.Buffer. Fix a latent bug this exposed: the destination pipeline is envelope-based, but only protobufList was registered as an EnvelopeMarshaller, so `-marshal protoJson|protoText|msgpack -dest <any>` nil-deref panicked at flushEnvelope. Register envelope-level marshallers for all three; protoJson uses protojson.Marshal (compact, one object per line). - pkg/xtcp/destinations_stdout.go: writerDest (io.Writer seam) + stdout factory - pkg/xtcp/destinations_core.go: schemeStdout const + knownSchemes - pkg/xtcp/input_validation.go: treat stdout like null (bare + ":"-suffixed) - pkg/xtcp/marshallers.go: envelope protoJson/protoText/msgpack marshallers - cmd/xtcp2: mention stdout in -dest help - tests for the writer seam, error paths, factory, validation, and envelope JSON output (valid one-line JSON with a row array) Verified end-to-end in a container: `-dest stdout -marshal protoJson -d 1` prints one-line JSON envelopes of real host sockets to stdout (logs stay on stderr; config dump only at -d >10). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Summary
Adds a
stdoutdestination so xtcp2 can print socket data to its own stdout — e.g.:streams one JSON
Envelopeper poll cycle as NDJSON. Great for local development, debugging, and piping tojq. In Docker, the daemon's records appear directly indocker logs(logs go to stderr, so stdout carries only the JSON).What's included
io.Writer-basedwriterDest(defaultos.Stdout) instead of copying the null/udpSend/Closeboilerplate. A futurestderr/file sink is a one-line factory over the same type. Theio.Writerseam is also the test seam (inject abytes.Buffer).protobufListwas registered as anEnvelopeMarshaller. So-marshal protoJson|protoText|msgpackwith any destination nil-deref panicked atflushEnvelope. This registers envelope-level marshallers for all three;protoJsonusesprotojson.Marshal(compact, one object per line).stdoutis treated likenull(both barestdoutandstdout:accepted).-desthelp mentionsstdout.Tests
writerDestframing (payload + newline, no buffer mutation), both write-error branches, and factory wiring — all via theio.Writerseam, noos.Stdoutjuggling.rowarray.stdout/stdout:.Verification
nix build .#test-pkg-xtcp,.#test-cmd-xtcp2,.#checks.x86_64-linux.golangci-lintall pass.-dest stdout -marshal protoJson -d 1printed one-line JSON envelopes of real host sockets (105 rows, fulltcp_info/ congestion / skmem / cgroup fields) to stdout.🤖 Generated with Claude Code