handle hex session id

This commit is contained in:
ShiBen
2022-03-30 15:46:05 +08:00
committed by Alessandro Ros
parent e292718307
commit 6b0f7b84bb
2 changed files with 68 additions and 3 deletions

View File

@@ -99,9 +99,12 @@ func (s *SessionDescription) unmarshalOrigin(value string) error {
var sessionID uint64 var sessionID uint64
var err error var err error
if strings.HasPrefix(fields[1], "0x") { switch {
sessionID, err = strconv.ParseUint(fields[1][len("0x"):], 16, 64) case strings.HasPrefix(fields[1], "0x") || strings.HasPrefix(fields[1], "0X"):
} else { sessionID, err = strconv.ParseUint(fields[1][2:], 16, 64)
case strings.ContainsAny(fields[1], "abcdefABCDEF"):
sessionID, err = strconv.ParseUint(fields[1], 16, 64)
default:
sessionID, err = strconv.ParseUint(fields[1], 10, 64) sessionID, err = strconv.ParseUint(fields[1], 10, 64)
} }
if err != nil { if err != nil {

View File

@@ -1382,6 +1382,68 @@ var cases = []struct {
}, },
}, },
}, },
{
"hex session id for 0XAC4EC96E",
[]byte("v=0\r\n" +
"o=jdoe 0XAC4EC96E 2890842807 IN IP4 10.47.16.5\r\n" +
"s=SDP Seminar\r\n" +
"i=A Seminar on the session description protocol\r\n" +
"t=3034423619 3042462419\r\n"),
[]byte("v=0\r\n" +
"o=jdoe 2890844526 2890842807 IN IP4 10.47.16.5\r\n" +
"s=SDP Seminar\r\n" +
"i=A Seminar on the session description protocol\r\n" +
"t=3034423619 3042462419\r\n"),
SessionDescription{
Origin: psdp.Origin{
Username: "jdoe",
SessionID: 2890844526,
SessionVersion: 2890842807,
NetworkType: "IN",
AddressType: "IP4",
UnicastAddress: "10.47.16.5",
},
SessionName: "SDP Seminar",
SessionInformation: func() *psdp.Information {
v := psdp.Information("A Seminar on the session description protocol")
return &v
}(),
TimeDescriptions: []psdp.TimeDescription{
{psdp.Timing{3034423619, 3042462419}, nil},
},
},
},
{
"hex session id for 103bdb6f",
[]byte("v=0\r\n" +
"o=jdoe 103bdb6f 2890842807 IN IP4 10.47.16.5\r\n" +
"s=SDP Seminar\r\n" +
"i=A Seminar on the session description protocol\r\n" +
"t=3034423619 3042462419\r\n"),
[]byte("v=0\r\n" +
"o=jdoe 272358255 2890842807 IN IP4 10.47.16.5\r\n" +
"s=SDP Seminar\r\n" +
"i=A Seminar on the session description protocol\r\n" +
"t=3034423619 3042462419\r\n"),
SessionDescription{
Origin: psdp.Origin{
Username: "jdoe",
SessionID: 272358255,
SessionVersion: 2890842807,
NetworkType: "IN",
AddressType: "IP4",
UnicastAddress: "10.47.16.5",
},
SessionName: "SDP Seminar",
SessionInformation: func() *psdp.Information {
v := psdp.Information("A Seminar on the session description protocol")
return &v
}(),
TimeDescriptions: []psdp.TimeDescription{
{psdp.Timing{3034423619, 3042462419}, nil},
},
},
},
} }
func TestUnmarshal(t *testing.T) { func TestUnmarshal(t *testing.T) {