diff --git a/core.go b/core.go new file mode 100644 index 00000000..fd2e443d --- /dev/null +++ b/core.go @@ -0,0 +1,58 @@ +package ws + +import ( + "io" +) + +// This is how it is capitalized in the RFC. +type Opcode int + +const ( + Continuation Opcode = iota + Text + Binary + // 3 - 7 are reserved for further non-control frames. + Close = 8 + Ping + Pong + // 11-16 are reserved for further control frames. +) + +type Header struct { + FIN bool + + RSV1 bool + RSV2 bool + RSV3 bool + + Opcode Opcode + + // Length is an integer because the RFC mandates the MSB bit cannot be set. + // So we cannot send or receive a frame with negative length. + Length int64 + + Masked bool + Mask [4]byte +} + +func (f *Header) Bytes() []byte { + panic("TODO") +} + +func (f *Header) MaskPayload(payload []byte) { + panic("TODO") +} + +func ReadHeader(w io.Writer) (Header, error) { + panic("TODO") +} + +type StatusCode uint16 + +const ( + NormalClosure StatusCode = 1000 + iota + GoingAway + ProtocolError + UnsupportedData + // ... +) diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..44649774 --- /dev/null +++ b/go.mod @@ -0,0 +1 @@ +module nhooyr.io/ws diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..e69de29b diff --git a/ws.go b/ws.go new file mode 100644 index 00000000..ee3e9da1 --- /dev/null +++ b/ws.go @@ -0,0 +1,24 @@ +package ws + +import ( + "bufio" + "io" + "net" + "net/http" +) + +func Writer(w bufio.Writer, typ Opcode) io.WriteCloser { + panic("TODO") +} + +func WriteFrame(w io.Writer, typ Opcode, p []byte) error { + panic("TODO") +} + +func ReadFrame(r io.Reader) (typ Opcode, payload io.Reader, err error) { + panic("TODO") +} + +func Upgrade(w http.ResponseWriter, r *http.Request) (net.Conn, *bufio.ReadWriter, error) { + panic("TODO") +}