-
Notifications
You must be signed in to change notification settings - Fork 11
/
sessionDataItem.go
42 lines (35 loc) · 1.09 KB
/
sessionDataItem.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package m3u8
import (
"fmt"
"strings"
)
// SessionDataItem represents a set of EXT-X-SESSION-DATA attributes
type SessionDataItem struct {
DataID string
Value *string
URI *string
Language *string
}
// NewSessionDataItem parses a text line and returns a *SessionDataItem
func NewSessionDataItem(text string) (*SessionDataItem, error) {
attributes := ParseAttributes(text)
return &SessionDataItem{
DataID: attributes[DataIDTag],
Value: pointerTo(attributes, ValueTag),
URI: pointerTo(attributes, URITag),
Language: pointerTo(attributes, LanguageTag),
}, nil
}
func (sdi *SessionDataItem) String() string {
slice := []string{fmt.Sprintf(quotedFormatString, DataIDTag, sdi.DataID)}
if sdi.Value != nil {
slice = append(slice, fmt.Sprintf(quotedFormatString, ValueTag, *sdi.Value))
}
if sdi.URI != nil {
slice = append(slice, fmt.Sprintf(quotedFormatString, URITag, *sdi.URI))
}
if sdi.Language != nil {
slice = append(slice, fmt.Sprintf(quotedFormatString, LanguageTag, *sdi.Language))
}
return fmt.Sprintf(`%s:%s`, SessionDataItemTag, strings.Join(slice, ","))
}