Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions core.go
Original file line number Diff line number Diff line change
@@ -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
// ...
)
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module nhooyr.io/ws
Empty file added go.sum
Empty file.
24 changes: 24 additions & 0 deletions ws.go
Original file line number Diff line number Diff line change
@@ -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")
}