-
Notifications
You must be signed in to change notification settings - Fork 295
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
codecgen ignores struct tags for struct field renaming #60
Comments
The only problem is with the codec-generated one from what i see. i.e. codec generated one doesn't take the struct tags into account. Is that correct? If so, can you ensure that you have the latest version of codecgen? Do a 'go get -u github.com/ugorji/go/codec/codecgen github.com/ugorji/go/codec' |
i.e. if you do a t.Key="whynot" Then you will see that both runtime-introspection (reflection) modes work the same. The only discrepancy is in the generated code, as it looks like it does honor the struct tags. I believe this was fixed a while back, which is why I want you to try and re-update, to see if the issue currently exists, before i look deeper. Thanks much. |
Hey Ugorij, Yes, you're right. Only 1 issue. I didn't set the Key field of the second struct I was testing. With the codec generated code:
|
I ran the following commands
I still received incorrect output for the generated code. The reflection based code came out correct though. I updated my original post to reflect this. |
@starJammer Please try now with updates and let me kow that it works. Thanks. |
I think things are worse now. The codecgen command is spitting out an error and two very small files are being generated when I use the -x option. Command I ran:
The codecgen-main-1429668731680257800.generated.go file//+build ignore
package main
import "bitbucket.org/starJammer/tester/model"
func main() {
model.CodecGenTempWrite1429668731680257800()
} The codecgen-pkg-1429668731680257800.generated.go file//+build codecgen
package model
import (
codec1978 "github.com/ugorji/go/codec"
"os"
"reflect"
"bytes"
"go/format"
)
func CodecGenTempWrite1429668731680257800() {
fout, err := os.Create("codec_gen.go")
if err != nil {
panic(err)
}
defer fout.Close()
var out bytes.Buffer
var typs []reflect.Type
var t0 Test
typs = append(typs, reflect.TypeOf(t0))
var t1 Next
typs = append(typs, reflect.TypeOf(t1))
codec1978.Gen(&out, "", "model", false, typs...)
bout, err := format.Source(out.Bytes())
if err != nil {
fout.Write(out.Bytes())
panic(err)
}
fout.Write(bout)
} |
We already ensure that we generate a transient method name to call. No need to use build tags to restrict it, as that requires each codecgen user to pass the -rt codecgen flag when calling codecgen. Resolves #60
The codecgen-pkg-1429668731680257800.generated.go should not have had the //+build codecgen, This should be resolved now. Please retry. Thanks. |
The resolves it. Thank you for the amazing support.
|
Hi, I've been looking at codec recently and was testing it out but was getting some behavior differences between it and encoding/json. Here is the output I'm getting using the same structs.
Below is my example code and directory structure
root
|----main.go
|----model
|--------model.go
The main.go file
Here is the model.go file
The text was updated successfully, but these errors were encountered: