2022-10-11 17:36:09 +08:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
coder "git.hpds.cc/Component/mq_coder"
|
|
|
|
"git.hpds.cc/Component/network/frame"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ParseFrame parses the frame from QUIC stream.
|
|
|
|
func ParseFrame(stream io.Reader) (frame.Frame, error) {
|
|
|
|
buf, err := coder.ReadPacket(stream)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
frameType := buf[0]
|
|
|
|
switch frameType {
|
|
|
|
case 0x80 | byte(frame.TagOfHandshakeFrame):
|
2023-04-05 16:15:59 +08:00
|
|
|
return frame.DecodeToHandshakeFrame(buf)
|
2022-10-11 17:36:09 +08:00
|
|
|
case 0x80 | byte(frame.TagOfDataFrame):
|
2023-04-05 16:15:59 +08:00
|
|
|
return frame.DecodeToDataFrame(buf)
|
2022-10-11 17:36:09 +08:00
|
|
|
case 0x80 | byte(frame.TagOfAcceptedFrame):
|
|
|
|
return frame.DecodeToAcceptedFrame(buf)
|
|
|
|
case 0x80 | byte(frame.TagOfRejectedFrame):
|
|
|
|
return frame.DecodeToRejectedFrame(buf)
|
|
|
|
case 0x80 | byte(frame.TagOfGoawayFrame):
|
|
|
|
return frame.DecodeToGoawayFrame(buf)
|
|
|
|
case 0x80 | byte(frame.TagOfBackFlowFrame):
|
|
|
|
return frame.DecodeToBackFlowFrame(buf)
|
2023-04-05 16:15:59 +08:00
|
|
|
case 0x80 | byte(frame.TagOfHandshakeAckFrame):
|
|
|
|
return frame.DecodeToHandshakeAckFrame(buf)
|
|
|
|
case 0x80 | byte(frame.TagOfAuthenticationFrame):
|
|
|
|
return frame.DecodeToAuthenticationFrame(buf)
|
|
|
|
case 0x80 | byte(frame.TagOfAuthenticationAckFrame):
|
|
|
|
return frame.DecodeToAuthenticationRespFrame(buf)
|
|
|
|
case 0x80 | (byte(frame.TagOfCloseStreamFrame)):
|
|
|
|
return frame.DecodeToCloseStreamFrame(buf)
|
2022-10-11 17:36:09 +08:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unknown frame type, buf[0]=%#x", buf[0])
|
|
|
|
}
|
|
|
|
}
|