Coder Social home page Coder Social logo

CCR - Event-Timestamp about go-diameter HOT 11 CLOSED

fiorix avatar fiorix commented on June 3, 2024
CCR - Event-Timestamp

from go-diameter.

Comments (11)

fiorix avatar fiorix commented on June 3, 2024

Can you paste the struct or at least the field? I was looking at the reflect tests and realised we don't actually have a test for time.Time although it should be supported. Perhaps you can try *AVP?

from go-diameter.

aaronchar avatar aaronchar commented on June 3, 2024

sure so this is my struct I am trying to use (or a part of it anyway). I will give *AVP a shot to see what happens.

type ccr struct {
    EventTimestamp                time.Time      `avp:"Event-Timestamp"`
    SessionID                     string             `avp:"Session-Id"`
    OriginHost                    string             `avp:"Origin-Host"`
    OriginRealm                   string             `avp:"Origin-Realm"`
    DestinationRealm              string             `avp:"Destination-Realm"`
    AuthApplicationID             int32              `avp:"Auth-Application-Id"`
    ServiceContextID              string             `avp:"Service-Context-Id"`
    CCRequestType                 int32              `avp:"CC-Request-Type"`
    CCRequestNumber               int32              `avp:"CC-Request-Number"`
    DestinationHost               string             `avp:"Destination-Host"`
}

from go-diameter.

fiorix avatar fiorix commented on June 3, 2024

That's what I suspected. So, try first changing from time.Time to datatype.Time and you should get the right value. I believe we don't have the right conversion from AVP to time.Time in reflect.go. You could probably add that, and a unit test.

from go-diameter.

aaronchar avatar aaronchar commented on June 3, 2024

actually I had tried datatype.Time and it gives me the same result

from go-diameter.

aaronchar avatar aaronchar commented on June 3, 2024
type ccr struct {
    EventTimestamp                datatype.Time      `avp:"Event-Timestamp"`
    SessionID                     string             `avp:"Session-Id"`
    OriginHost                    string             `avp:"Origin-Host"`
    OriginRealm                   string             `avp:"Origin-Realm"`
    DestinationRealm              string             `avp:"Destination-Realm"`
    AuthApplicationID             int32              `avp:"Auth-Application-Id"`
    ServiceContextID              string             `avp:"Service-Context-Id"`
    CCRequestType                 int32              `avp:"CC-Request-Type"`
    CCRequestNumber               int32              `avp:"CC-Request-Number"`
    DestinationHost               string             `avp:"Destination-Host"`
}

Results in

Time{0001-01-01 00:00:00 +0000 UTC}
Time{0001-01-01 00:00:00 +0000 UTC}
Time{0001-01-01 00:00:00 +0000 UTC}
Time{0001-01-01 00:00:00 +0000 UTC}
Time{0001-01-01 00:00:00 +0000 UTC}
Time{0001-01-01 00:00:00 +0000 UTC}
Time{0001-01-01 00:00:00 +0000 UTC}
Time{0001-01-01 00:00:00 +0000 UTC}

Where as manually using msg.FindAVP(avp.EventTimestamp, 0) comes out with the following

Time{2016-02-27 17:23:16 -0600 CST}
Time{2016-02-27 17:23:16 -0600 CST}
Time{2016-02-27 17:23:16 -0600 CST}
Time{2016-02-27 17:23:16 -0600 CST}
Time{2016-02-27 17:23:16 -0600 CST}

from go-diameter.

fiorix avatar fiorix commented on June 3, 2024

Right, so something messed up in reflect.go. We should definitely have a test for that.

from go-diameter.

jaroszan avatar jaroszan commented on June 3, 2024

I have added test as follows (not sure yet how to fix reflect.go):

func TestUnmarshalTimeDatatype(t *testing.T) {
    expectedTime := "Time{2015-12-09 16:40:53 +0100 CET}"
    m, _ := ReadMessage(bytes.NewReader(testMessageWithVendorID), dict.Default)
    type Data struct {
        EventTimestamp datatype.Time `avp:"Event-Timestamp"`
    }
    var d Data
    if err := m.Unmarshal(&d); err != nil {
        t.Fatal(err)
    }
    if d.EventTimestamp.String() != expectedTime {
        t.Fatalf("Unexpected value, want %s, have %s", expectedTime, d.EventTimestamp.String())
    }
}

from go-diameter.

fiorix avatar fiorix commented on June 3, 2024

In order to fix reflect.go we have to look for the avp name in the field tag, ensure that the field is a time field in the dictionary, then decide what to do based on the field type. It already supports AVP and *AVP but does not support datatype.Time and time.Time.

from go-diameter.

jaroszan avatar jaroszan commented on June 3, 2024

@fiorix / @DefunctExodus - should this one be closed by #66? Or is there something else to be done?

from go-diameter.

fiorix avatar fiorix commented on June 3, 2024

I believe so

from go-diameter.

aaronchar avatar aaronchar commented on June 3, 2024

This can be closed now, Sorry I have not had a ton of time to play with it lately

from go-diameter.

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.