data.go 724 B

123456789101112131415161718192021222324252627282930
  1. package proto
  2. import "github.com/pion/stun"
  3. // Data represents DATA attribute.
  4. //
  5. // The DATA attribute is present in all Send and Data indications. The
  6. // value portion of this attribute is variable length and consists of
  7. // the application data (that is, the data that would immediately follow
  8. // the UDP header if the data was been sent directly between the client
  9. // and the peer).
  10. //
  11. // RFC 5766 Section 14.4
  12. type Data []byte
  13. // AddTo adds DATA to message.
  14. func (d Data) AddTo(m *stun.Message) error {
  15. m.Add(stun.AttrData, d)
  16. return nil
  17. }
  18. // GetFrom decodes DATA from message.
  19. func (d *Data) GetFrom(m *stun.Message) error {
  20. v, err := m.Get(stun.AttrData)
  21. if err != nil {
  22. return err
  23. }
  24. *d = v
  25. return nil
  26. }