Make printer more flexible, allow very-compact forms #574
+177
−118
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.
I'm attempting here to make something that lets me see the forms of a block without looking at the matrix and without it getting too out of hand when the block is complex.
See printer/printer_test.go for examples of what this is doing. There's some breakage here, however, so @warpfork you might want to weigh in if you still care about the
printer
package:foo:string{"bar"}
or10:string{"bar"}
)Indentation
if it's leftnil
, it just means there's no indentation, you have to set it. The default package-exposed functions set it to\t
though.Indentation
isnil
, then we also don't print newlines; similar to the behaviour of encoding/json and also the JSJSON.stringify
.OmitScalarValues
optionAs per test example, a basic
Config{OmitScalarValues: true}
would give you the most compact form:map{string:string,string:string,string:map{string:string,string:string},string:list{0:int,1:int},string:list{0:float}}
So far, the most complex thing I've printed with this is a Filecoin HAMT root with embedded
SectorPreCommitOnChainInfo
(tuple representation) values in it:list{0:bytes,1:list{0:list{0:list{0:bytes,1:list{0:list{0:int,1:int,2:link,3:int,4:list{},5:int,6:link},1:bytes,2:int}},1:list{0:bytes,1:list{0:list{0:int,1:int,2:link,3:int,4:list{},5:int,6:link},1:bytes,2:int}}},1:list{0:list{0:bytes,1:list{0:list{0:int,1:int,2:link,3:int,4:list{},5:int,6:link},1:bytes,2:int}},1:list{0:bytes,1:list{0:list{0:int,1:int,2:link,3:int,4:list{},5:int,6:link},1:bytes,2:int}}},2:list{0:list{0:bytes,1:list{0:list{0:int,1:int,2:link,3:int,4:list{},5:int,6:link},1:bytes,2:int}}},3:list{0:list{0:bytes,1:list{0:list{0:int,1:int,2:link,3:int,4:list{},5:int,6:link},1:bytes,2:int}}},4:list{0:list{0:bytes,1:list{0:list{0:int,1:int,2:link,3:int,4:list{},5:int,6:link},1:bytes,2:int}}}}}
It's still a little bit like looking in the matrix but it's more helpful than printing out CBOR diagnostic output and I'm yet to properly build a set of schemas to match these against.