-
Notifications
You must be signed in to change notification settings - Fork 57
/
unmarshal_cache.go
44 lines (37 loc) · 1.17 KB
/
unmarshal_cache.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
43
44
// 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
}