File: sessionDataItem.go

package info (click to toggle)
golang-github-etherlabsio-go-m3u8 1.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 348 kB
  • sloc: makefile: 3
file content (42 lines) | stat: -rw-r--r-- 1,118 bytes parent folder | download | duplicates (2)
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, ","))
}