diff --git a/README.md b/README.md index d0edcc0c..8b0508a1 100644 --- a/README.md +++ b/README.md @@ -261,6 +261,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu * [Dean Eigenmann](https://github.com/decanus) * [Cameron Elliott](https://github.com/cameronelliott) * [Pascal Benoit](https://github.com/pascal-ace) +* [Mats](https://github.com/Mindgamesnl) ### License MIT License - see [LICENSE](LICENSE) for full text diff --git a/sessiondescription.go b/sessiondescription.go index ea8927e0..5b933915 100644 --- a/sessiondescription.go +++ b/sessiondescription.go @@ -13,12 +13,8 @@ type SessionDescription struct { parsed *sdp.SessionDescription } -// Unmarshal is a helper to deserialize the sdp, and re-use it internally -// if required +// Unmarshal is a helper to deserialize the sdp func (sd *SessionDescription) Unmarshal() (*sdp.SessionDescription, error) { - if sd.parsed != nil { - return sd.parsed, nil - } sd.parsed = &sdp.SessionDescription{} err := sd.parsed.Unmarshal([]byte(sd.SDP)) return sd.parsed, err diff --git a/sessiondescription_test.go b/sessiondescription_test.go index 446f69a8..6ac5828e 100644 --- a/sessiondescription_test.go +++ b/sessiondescription_test.go @@ -2,6 +2,7 @@ package webrtc import ( "encoding/json" + "reflect" "testing" "github.com/stretchr/testify/assert" @@ -68,12 +69,15 @@ func TestSessionDescription_Unmarshal(t *testing.T) { SDP: offer.SDP, } assert.Nil(t, desc.parsed) - parsed, err := desc.Unmarshal() - assert.NotNil(t, parsed) + parsed1, err := desc.Unmarshal() + assert.NotNil(t, parsed1) assert.NotNil(t, desc.parsed) assert.NoError(t, err) - parsed, err = desc.Unmarshal() - assert.NotNil(t, parsed) - assert.NoError(t, err) + parsed2, err2 := desc.Unmarshal() + assert.NotNil(t, parsed2) + assert.NoError(t, err2) assert.NoError(t, pc.Close()) + + // check if the two parsed results _really_ match, could be affected by internal caching + assert.True(t, reflect.DeepEqual(parsed1, parsed2)) }