Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make printer more flexible, allow very-compact forms #574

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

rvagg
Copy link
Member

@rvagg rvagg commented Jan 7, 2025

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:

  • Always add commas between list/map items (except for the last one)
  • Remove the space between the index/key and the value (so it's always like foo:string{"bar"} or 10:string{"bar"})
  • Don't change Indentation if it's left nil, it just means there's no indentation, you have to set it. The default package-exposed functions set it to \t though.
  • If Indentation is nil, then we also don't print newlines; similar to the behaviour of encoding/json and also the JS JSON.stringify.
  • Add an OmitScalarValues option

As 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.

@rvagg
Copy link
Member Author

rvagg commented Jan 7, 2025

One adjustment that might be worth making here is adding back the space after : when there is indenting, otherwise compress it. I'm fine with this as it is but encoding/json and JSON.stringify also have this behaviour I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant