Files

37 lines
832 B
Go
Raw Permalink Normal View History

2023-04-18 13:42:05 +02:00
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
2019-05-20 21:32:01 +03:00
package ice
2020-09-17 03:21:19 +00:00
import (
"encoding/binary"
2023-09-08 07:37:04 +00:00
"github.com/pion/stun/v2"
2020-09-17 03:21:19 +00:00
)
2019-05-20 21:32:01 +03:00
// PriorityAttr represents PRIORITY attribute.
type PriorityAttr uint32
const prioritySize = 4 // 32 bit
// AddTo adds PRIORITY attribute to message.
func (p PriorityAttr) AddTo(m *stun.Message) error {
v := make([]byte, prioritySize)
2020-09-17 03:21:19 +00:00
binary.BigEndian.PutUint32(v, uint32(p))
2019-05-20 21:32:01 +03:00
m.Add(stun.AttrPriority, v)
return nil
}
// GetFrom decodes PRIORITY attribute from message.
func (p *PriorityAttr) GetFrom(m *stun.Message) error {
v, err := m.Get(stun.AttrPriority)
if err != nil {
return err
}
if err = stun.CheckSize(stun.AttrPriority, len(v), prioritySize); err != nil {
return err
}
2020-09-17 03:21:19 +00:00
*p = PriorityAttr(binary.BigEndian.Uint32(v))
2019-05-20 21:32:01 +03:00
return nil
}