Comments (8)
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'
from go.
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.
from go.
Hey Ugorij,
Thanks for responding. I downloaded the code this morning with the -u option so I doubt that is the issue. Today was also the first time I ran go get. I'll update the code again anyway using the command you gave me just to be safe.
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:
- Yes, the struct tags aren't taken into account. Specifically, they are using the struct field names instead
from go.
I ran the following commands
rm codecgen
in the bin directory where it was installed. In my $GO_BINgo get -u github.com/ugorji/go/codec/codecgen github.com/ugorji/go/codec
codecgen -o codec_gen.go model.go
to regenerate the generated code.go build main.go
in root to build./main
to run the program.
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.
from go.
@starJammer Please try now with updates and let me kow that it works.
Thanks.
from go.
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: codecgen -x=true -o=codec_gen.go model.go
codecgen error: Error running go run codecgen-main-1429668731680257800.generated.go. Error: exit status 2. stdout/err: # command-line-arguments
./codecgen-main-1429668731680257800.generated.go:6: undefined: model.CodecGenTempWrite1429668731680257800
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)
}
from go.
The codecgen-pkg-1429668731680257800.generated.go should not have had the //+build codecgen,
as that would require that each call to codecgen passes the '-rt codecgen' option.
This should be resolved now.
Please retry.
Thanks.
from go.
The resolves it. Thank you for the amazing support.
Encodings from codec generated selfer code....
{"_key":"thing"}
{"_key":"whynot","_id":"another"}
Encodings from codec reflection based encoding....
{"_key":"thing"}
{"_id":"another","_key":"whynot"}
Encodings from encoding/json....
{"_key":"thing"}
{"_key":"whynot","_id":"another"}
from go.
Related Issues (20)
- codec.MsgpackHandle.RawToString is confusingly named HOT 2
- Go 1.20 - invalid memory address or nil pointer dereference HOT 5
- Msgpack deserialization with codecgen produces wrong result HOT 3
- Unexpected encoding with interface{} key using Canonical and MapKeyAsString.
- Decoding a slice of structs encoded as arrays into a slice of structs without the same number of fields HOT 2
- Duplicate key inside of a map triggers a "cannot decode unsigned integer" msgpack decode error HOT 1
- Efficient direct conversion between supported formats? HOT 2
- Expose Handle.Name() in some form through Encoder and Decoder for use by codec.Selfer HOT 1
- `io.ErrUnexpectedEOF` should be returned instead of `io.EOF` when only partial data is present
- Add `DecodeOptions.IntType` and `DecodeOptions.FloatType` ? HOT 1
- Docs do not seem to mention case-sensitive field handling
- mem leak? HOT 1
- Tests use rand.Intn(1) for boolean rand, but always returns 0
- Decoder accepts indefinite-length CBOR strings containing chunks with mismatched major types HOT 1
- UTF-8 validation isn't applied to CBOR text strings nested inside an indefinite-length text string HOT 2
- Add support for github.com/go-json-experiment/json / UnmarshalerV2 ? HOT 1
- runtime error with golang master (furture go 1.22)
- Leading zeros is not allowed in rfc7159
- attr.go
- [Question] Big Endian architecture
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go.