priority.go 829 B

123456789101112131415161718192021222324252627282930313233343536
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. package ice
  4. import (
  5. "encoding/binary"
  6. "github.com/pion/stun"
  7. )
  8. // PriorityAttr represents PRIORITY attribute.
  9. type PriorityAttr uint32
  10. const prioritySize = 4 // 32 bit
  11. // AddTo adds PRIORITY attribute to message.
  12. func (p PriorityAttr) AddTo(m *stun.Message) error {
  13. v := make([]byte, prioritySize)
  14. binary.BigEndian.PutUint32(v, uint32(p))
  15. m.Add(stun.AttrPriority, v)
  16. return nil
  17. }
  18. // GetFrom decodes PRIORITY attribute from message.
  19. func (p *PriorityAttr) GetFrom(m *stun.Message) error {
  20. v, err := m.Get(stun.AttrPriority)
  21. if err != nil {
  22. return err
  23. }
  24. if err = stun.CheckSize(stun.AttrPriority, len(v), prioritySize); err != nil {
  25. return err
  26. }
  27. *p = PriorityAttr(binary.BigEndian.Uint32(v))
  28. return nil
  29. }