pp icon indicating copy to clipboard operation
pp copied to clipboard

shorten result print for struct generated by protobuf

Open learningpro opened this issue 1 year ago • 5 comments

if an object has a type generated by protobuf, then the pp.Print() will show very very very long content on screen.

It would be better to show the user-defined fields.

learningpro avatar Sep 14 '23 07:09 learningpro

Can you share an example code (ideally a repository) to reproduce your current situation, the output it currently generates, a proposed API you'd like to use, and the output it would generate?

k0kubun avatar Sep 14 '23 22:09 k0kubun

@k0kubun

Can you share an example code (ideally a repository) to reproduce your current situation, the output it currently generates, a proposed API you'd like to use, and the output it would generate?

Sure. I found a repo in Github. https://github.com/kfelter/protobuf-example/tree/main The steps are:

  1. clone this repo and edit main.go
  2. add "github.com/k0kubun/pp" in import
  3. add pp.Println(events) at the end of main function.
  4. run go mod tidy and go build , it will generate a binary protobuf-example
  5. run ./protobuf-example and there will be a very very long output like this: image

learningpro avatar Sep 18 '23 08:09 learningpro

Thanks for providing:

share an example code (ideally a repository) to reproduce your current situation, the output it currently generates

can you also provide the other part?:

a proposed API you'd like to use, and the output it would generate

As of now, only you can guess what you want, so only you can implement this feature. I can review a pull request if writing it is easier than doing the above.

k0kubun avatar Sep 21 '23 06:09 k0kubun

Thanks for providing:

share an example code (ideally a repository) to reproduce your current situation, the output it currently generates

can you also provide the other part?:

a proposed API you'd like to use, and the output it would generate

As of now, only you can guess what you want, so only you can implement this feature. I can review a pull request if writing it is easier than doing the above.

@k0kubun I don't know how pp get each field, Could you point out which piece of code I should refer to and learn from. Than I may create a PR for it.

learningpro avatar Sep 22 '23 07:09 learningpro

This is the place where pp gets each field: https://github.com/k0kubun/pp/blob/6f55b4dc4b268e1f0c695978898e5bb3f901c322/printer.go#L235-L249

k0kubun avatar Sep 22 '23 07:09 k0kubun