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

tlb: register type with custom name #136

Merged
merged 4 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<img align="right" width="425px" src="https://github.com/xssnick/props/blob/master/logoimg.png?raw=true">

[![Based on TON][ton-svg]][ton]
![Coverage](https://img.shields.io/badge/Coverage-73.5%25-brightgreen)
![Coverage](https://img.shields.io/badge/Coverage-73.4%25-brightgreen)

Golang library for interacting with TON blockchain.

Expand Down
15 changes: 12 additions & 3 deletions tlb/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ var registered = map[string]reflect.Type{}

var magicType = reflect.TypeOf(Magic{})

func Register(typ any) {
t := reflect.TypeOf(typ)
func register(name string, t reflect.Type) {
magic := t.Field(0)
if magic.Type != magicType {
panic("first field is not magic")
Expand All @@ -21,5 +20,15 @@ func Register(typ any) {
panic("invalid magic tag")
}

registered[t.Name()] = t
registered[name] = t
}

func RegisterWithName(name string, typ any) {
t := reflect.TypeOf(typ)
register(name, t)
}

func Register(typ any) {
t := reflect.TypeOf(typ)
register(t.Name(), t)
}
Loading