2022-06-05 22:07:24 +00:00
|
|
|
package handshake
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
// C0S0 is a C0 or S0 packet.
|
2023-08-10 19:06:51 +00:00
|
|
|
type C0S0 struct {
|
|
|
|
Version byte
|
|
|
|
}
|
2022-06-05 22:07:24 +00:00
|
|
|
|
|
|
|
// Read reads a C0S0.
|
2023-08-10 19:06:51 +00:00
|
|
|
func (c *C0S0) Read(r io.Reader) error {
|
2022-06-05 22:07:24 +00:00
|
|
|
buf := make([]byte, 1)
|
|
|
|
_, err := io.ReadFull(r, buf)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-08-10 19:06:51 +00:00
|
|
|
c.Version = buf[0]
|
|
|
|
|
|
|
|
if c.Version != 3 && c.Version != 6 {
|
|
|
|
return fmt.Errorf("invalid rtmp version (%d)", c.Version)
|
2022-06-05 22:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write writes a C0S0.
|
2023-08-10 19:06:51 +00:00
|
|
|
func (c C0S0) Write(w io.Writer) error {
|
|
|
|
_, err := w.Write([]byte{c.Version})
|
2022-06-05 22:07:24 +00:00
|
|
|
return err
|
|
|
|
}
|