2022-05-13 17:04:47 +00:00
|
|
|
package base
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Chunk1 is a type 1 chunk.
|
|
|
|
// The message stream ID is not
|
|
|
|
// included; this chunk takes the same stream ID as the preceding chunk.
|
|
|
|
// Streams with variable-sized messages (for example, many video
|
|
|
|
// formats) SHOULD use this format for the first chunk of each new
|
|
|
|
// message after the first.
|
|
|
|
type Chunk1 struct {
|
2022-05-13 22:11:01 +00:00
|
|
|
ChunkStreamID byte
|
|
|
|
TimestampDelta uint32
|
|
|
|
Type MessageType
|
|
|
|
BodyLen uint32
|
|
|
|
Body []byte
|
2022-05-13 17:04:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write writes the chunk.
|
2022-05-13 18:53:52 +00:00
|
|
|
func (c Chunk1) Write(w io.Writer) error {
|
2022-05-13 17:04:47 +00:00
|
|
|
header := make([]byte, 8)
|
2022-05-13 18:53:52 +00:00
|
|
|
header[0] = 1<<6 | c.ChunkStreamID
|
2022-05-13 22:11:01 +00:00
|
|
|
header[1] = byte(c.TimestampDelta >> 16)
|
|
|
|
header[2] = byte(c.TimestampDelta >> 8)
|
|
|
|
header[3] = byte(c.TimestampDelta)
|
2022-05-13 18:53:52 +00:00
|
|
|
header[4] = byte(c.BodyLen >> 16)
|
|
|
|
header[5] = byte(c.BodyLen >> 8)
|
|
|
|
header[6] = byte(c.BodyLen)
|
2022-05-13 21:38:39 +00:00
|
|
|
header[7] = byte(c.Type)
|
2022-05-13 17:04:47 +00:00
|
|
|
_, err := w.Write(header)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-13 18:53:52 +00:00
|
|
|
_, err = w.Write(c.Body)
|
2022-05-13 17:04:47 +00:00
|
|
|
return err
|
|
|
|
}
|