Split Describe into DescribeList/DescribeWithCallback/Describe (Fixes #125) - #126
Merged
Conversation
…125) Introduce the utils/describe package (Unit, Nest, WithCallback, Printf) and refactor every structure's Describe into three layers: - DescribeList() []string content at indentation depth 0 - DescribeWithCallback(indent, prefixes each line and routes it to a printf) fmt.Printf-like callback - Describe(indent) delegates to DescribeWithCallback(indent, fmt.Printf); behavior unchanged Composite structures build their list by nesting each child's DescribeList one level deeper via describe.Nest, replacing the previous child.Describe (indent+1) calls. Output is byte-identical at indent 0.
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.
Linked Issue
Closes #125Root Cause
Every structure's
Describe(indent int)built its lines with an inlinestrings.Repeat(" │ ", indent)prefix and wrote them straight to stdout withfmt.Printf. Rendered content and rendering (indentation + output sink) were entangled, and composite types propagated the coupling by callingchild.Describe(indent+1). There was no way to obtain a description as data or route it to a non-stdout sink.Fix Description
Introduce a shared
utils/describepackage and split everyDescribeinto three layers:DescribeList() []string— the content at indentation depth 0 (source of truth). Composites build theirs by nesting each child'sDescribeListone level deeper viadescribe.Nest, replacing the oldchild.Describe(indent+1)calls.DescribeWithCallback(indent int, printf func(string, ...any) (int, error))— prependsindentindentation units to each line and routes it to afmt.Printf-like callback.Describe(indent int)— unchanged signature and behavior; delegates toDescribeWithCallback(indent, fmt.Printf).utils/describeprovidesUnit,Nest,WithCallback, and thePrintftype alias. The callback isfmt.Printf-shaped sofmt.Printfcan be passed directly, and any logger /fmt.Fprintfwrapper works as a sink.Converted all 15 implementations:
ace/mask,ace/header,ace/applicationdata,ace.AccessControlEntry,identity,sid,object(×3),acl(×4),securitydescriptor/header,securitydescriptor.NtSecurityDescriptor.How Verified
go build ./...,go vet ./...,gofmt -l— all clean.go test ./...— all packages pass, including existing describe/SDDL/round-trip suites.Describe(0)output equalsDescribeList()joined with newlines, and thatDescribeWithCallbackdelivers the same lines; a second test checks indent prefixing atindent=2.Test Coverage
Added:
utils/describe/describe_test.go(TestNest,TestWithCallback);securitydescriptor/NtSecurityDescriptor_describe_test.go(TestDescribeLayeringConsistency,TestDescribeIndentPrefix).Existing:
aceandsecuritydescriptordescribe tests continue to pass unchanged, confirming byte-identical output atindent=0.Scope of Change
utils/describe/describe.go(new),utils/describe/describe_test.go(new),securitydescriptor/NtSecurityDescriptor_describe_test.go(new), plus the 15 structure files listed above.indent=0.NtSecurityDescriptornow indents its root/footer line atindent>0(previously always column 0); this is unobservable at the normal top-levelDescribe(0)call.Risk and Rollout
Additive API (two new methods per type);
Describebehavior is preserved. Safe to merge — no wire-format or default-output changes.