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

Using Struct Tags to Control Encoding #58

Closed
heri16 opened this issue Jul 24, 2021 · 9 comments
Closed

Using Struct Tags to Control Encoding #58

heri16 opened this issue Jul 24, 2021 · 9 comments
Labels

Comments

@heri16
Copy link

heri16 commented Jul 24, 2021

How can we convert go native types into etf.Term via reflection? Is a reflection api included?

E.g. slices of map[string]interface{} to etf.Term?

@halturin
Copy link
Collaborator

halturin commented Jul 24, 2021

etf.Term is just an interface type. You don't need it. What exactly are you trying to do?

@heri16 heri16 changed the title Convert God's native to map Convert Go's native to map Jul 26, 2021
@heri16
Copy link
Author

heri16 commented Jul 28, 2021

I think I was looking for how go Structs can be converted to an etf.Map via annotations/tags just like the built-in json lib and aws-ion marshaller.

See: https://www.digitalocean.com/community/tutorials/how-to-use-struct-tags-in-go

@heri16 heri16 changed the title Convert Go's native to map Using Struct Tags to Control Encoding Jul 29, 2021
@heri16
Copy link
Author

heri16 commented Jul 29, 2021

We use *string extensively and ergo seems to crash when any nested value is a *string.

@halturin
Copy link
Collaborator

halturin commented Jul 29, 2021

Hmm. It's a very interesting case. Actually, the value should be dereferenced during the encoding process.
https://github.com/halturin/ergo/blob/master/etf/encode.go#L547

I'll take a look closer.

@halturin
Copy link
Collaborator

created issue #65

@halturin
Copy link
Collaborator

halturin commented Jul 29, 2021

I think I was looking for how go Structs can be converted to an etf.Map via annotations/tags just like the built-in json lib and aws-ion marshaller.

ETF encoder encodes any struct to the erlang map using field name as a key.
as an example this kind of value

type test struct {
	A string
}

will be encoded like this

#{'A' => "example"}

@halturin
Copy link
Collaborator

may I ask you to check out my fix of #65? just merged into the master

@heri16
Copy link
Author

heri16 commented Jul 30, 2021

Thanks for the quick response. It's amazing what this library could do if it takes off in the Elixir/Golang community.

We are using it to work with AWS services where the quality of the rust-native drivers are not yet production ready (to use with Rustler NIFs). The startup I work at is comfortable with Golang, but we know how much more productive a true functional language with pattern matching can be. So my sell to management is for Golang on the code paths were every extra ounce of performance is critical, combined with the robustness of OTP.

Will test out your fix over the weekend.

I'm also comfortable with golang so if you are open to contributions, let's formulate some guidelines.

@halturin
Copy link
Collaborator

not valid any more

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

No branches or pull requests

2 participants