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

Expose types #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
12 changes: 12 additions & 0 deletions codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ func NewCodec() *Codec {
return cdc
}

func (cdc *Codec) TypeInfos() map[reflect.Type]*TypeInfo {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have too much context here, but simply returning maps on a reference type is somewhat dangerous as the caller can unexpectedly modify the reference (i.e. the codec). Instead, return a copy of the map.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, let's add simple godocs.

return cdc.typeInfos
}

func (cdc *Codec) TypeInfosByName() map[string]*TypeInfo {
return cdc.nameToTypeInfo
}

func (cdc *Codec) DisFixToTypeInfo() map[DisfixBytes]*TypeInfo {
return cdc.disfixToTypeInfo
}

// This function should be used to register all interfaces that will be
// encoded/decoded by go-amino.
// Usage:
Expand Down