mirror of
https://github.com/aler9/gortsplib
synced 2025-10-20 13:55:30 +08:00
46
pkg/mikey/payload_rand.go
Normal file
46
pkg/mikey/payload_rand.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package mikey
|
||||
|
||||
import "fmt"
|
||||
|
||||
// PayloadRAND is a payload with random data.
|
||||
type PayloadRAND struct {
|
||||
Data []byte
|
||||
}
|
||||
|
||||
func (p *PayloadRAND) unmarshal(buf []byte) (int, error) {
|
||||
if len(buf) < 2 {
|
||||
return 0, fmt.Errorf("buffer too short")
|
||||
}
|
||||
|
||||
n := 1
|
||||
dataLen := int(buf[n])
|
||||
n++
|
||||
|
||||
if dataLen < 16 {
|
||||
return 0, fmt.Errorf("invalid data len: %v", dataLen)
|
||||
}
|
||||
|
||||
if len(buf[n:]) < dataLen {
|
||||
return 0, fmt.Errorf("buffer too short")
|
||||
}
|
||||
|
||||
p.Data = buf[n : n+dataLen]
|
||||
n += dataLen
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (*PayloadRAND) typ() payloadType {
|
||||
return payloadTypeRAND
|
||||
}
|
||||
|
||||
func (p *PayloadRAND) marshalSize() int {
|
||||
return 2 + len(p.Data)
|
||||
}
|
||||
|
||||
func (p *PayloadRAND) marshalTo(buf []byte) (int, error) {
|
||||
buf[1] = uint8(len(p.Data))
|
||||
n := 2
|
||||
n += copy(buf[2:], p.Data)
|
||||
return n, nil
|
||||
}
|
Reference in New Issue
Block a user