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

docs: guidelines for proto message's String() method #13364

Merged
merged 7 commits into from
Sep 22, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/core/encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ Module should register interfaces using `InterfaceRegistry` which provides a mec

In addition, an `UnpackInterfaces` phase should be introduced to deserialization to unpack interfaces before they're needed. Protobuf types that contain a protobuf `Any` either directly or via one of their members should implement the `UnpackInterfacesMessage` interface:

### Can I customize a proto Message's String() method
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved

We should never customize a proto Message's `String()` method, i.e. we should never use `option (gogoproto.goproto_stringer) = false;`, doing otherwise leads to unexpected behaviour like returning wrong output or missing fields in the output.
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
If we want to use a yaml output, then we should go through ProtoJSON, using the `JSONToYAML` function.
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
For example: https://github.com/cosmos/cosmos-sdk/blob/main/x/auth/types/account.go#L140-L152
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved

```go
type UnpackInterfacesMessage interface {
UnpackInterfaces(InterfaceUnpacker) error
Expand Down