Giter VIP home page Giter VIP logo

Comments (8)

ugorji avatar ugorji commented on May 23, 2024

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.

ugorji avatar ugorji commented on May 23, 2024

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.

starJammer avatar starJammer commented on May 23, 2024

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:

  1. Yes, the struct tags aren't taken into account. Specifically, they are using the struct field names instead

from go.

starJammer avatar starJammer commented on May 23, 2024

I ran the following commands

  1. rm codecgen in the bin directory where it was installed. In my $GO_BIN
  2. go get -u github.com/ugorji/go/codec/codecgen github.com/ugorji/go/codec
  3. codecgen -o codec_gen.go model.go to regenerate the generated code.
  4. go build main.go in root to build
  5. ./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.

ugorji avatar ugorji commented on May 23, 2024

@starJammer Please try now with updates and let me kow that it works.

Thanks.

from go.

starJammer avatar starJammer commented on May 23, 2024

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.

ugorji avatar ugorji commented on May 23, 2024

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.

starJammer avatar starJammer commented on May 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.