2022-07-17 13:17:18 +00:00
|
|
|
package message //nolint:dupl
|
2022-06-08 18:47:36 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/aler9/rtsp-simple-server/internal/rtmp/chunk"
|
|
|
|
"github.com/aler9/rtsp-simple-server/internal/rtmp/rawmessage"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MsgAcknowledge is an acknowledgement message.
|
|
|
|
type MsgAcknowledge struct {
|
|
|
|
Value uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal implements Message.
|
|
|
|
func (m *MsgAcknowledge) Unmarshal(raw *rawmessage.Message) error {
|
|
|
|
if raw.ChunkStreamID != ControlChunkStreamID {
|
|
|
|
return fmt.Errorf("unexpected chunk stream ID")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(raw.Body) != 4 {
|
|
|
|
return fmt.Errorf("unexpected body size")
|
|
|
|
}
|
|
|
|
|
2022-07-17 13:17:18 +00:00
|
|
|
m.Value = uint32(raw.Body[0])<<24 | uint32(raw.Body[1])<<16 | uint32(raw.Body[2])<<8 | uint32(raw.Body[3])
|
|
|
|
|
2022-06-08 18:47:36 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Marshal implements Message.
|
|
|
|
func (m *MsgAcknowledge) Marshal() (*rawmessage.Message, error) {
|
2022-07-17 13:17:18 +00:00
|
|
|
buf := make([]byte, 4)
|
|
|
|
|
|
|
|
buf[0] = byte(m.Value >> 24)
|
|
|
|
buf[1] = byte(m.Value >> 16)
|
|
|
|
buf[2] = byte(m.Value >> 8)
|
|
|
|
buf[3] = byte(m.Value)
|
2022-06-08 18:47:36 +00:00
|
|
|
|
|
|
|
return &rawmessage.Message{
|
|
|
|
ChunkStreamID: ControlChunkStreamID,
|
|
|
|
Type: chunk.MessageTypeAcknowledge,
|
2022-07-17 13:17:18 +00:00
|
|
|
Body: buf,
|
2022-06-08 18:47:36 +00:00
|
|
|
}, nil
|
|
|
|
}
|