File: unmarshal_cache.go

package info (click to toggle)
golang-github-pion-sdp 3.0.10-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 304 kB
  • sloc: makefile: 2
file content (48 lines) | stat: -rw-r--r-- 1,198 bytes parent folder | download
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
43
44
45
46
47
48
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package sdp

type unmarshalCache struct {
	sessionAttributes []Attribute
	mediaAttributes   []Attribute
}

func (c *unmarshalCache) reset() {
	c.sessionAttributes = c.sessionAttributes[:0]
	c.mediaAttributes = c.mediaAttributes[:0]
}

func (c *unmarshalCache) getSessionAttribute() *Attribute {
	c.sessionAttributes = append(c.sessionAttributes, Attribute{})

	return &c.sessionAttributes[len(c.sessionAttributes)-1]
}

func (c *unmarshalCache) cloneSessionAttributes() []Attribute {
	if len(c.sessionAttributes) == 0 {
		return nil
	}
	s := make([]Attribute, len(c.sessionAttributes))
	copy(s, c.sessionAttributes)
	c.sessionAttributes = c.sessionAttributes[:0]

	return s
}

func (c *unmarshalCache) getMediaAttribute() *Attribute {
	c.mediaAttributes = append(c.mediaAttributes, Attribute{})

	return &c.mediaAttributes[len(c.mediaAttributes)-1]
}

func (c *unmarshalCache) cloneMediaAttributes() []Attribute {
	if len(c.mediaAttributes) == 0 {
		return nil
	}
	s := make([]Attribute, len(c.mediaAttributes))
	copy(s, c.mediaAttributes)
	c.mediaAttributes = c.mediaAttributes[:0]

	return s
}