wire

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClosedStreamErr = fmt.Errorf("stream is closed")

Functions

This section is empty.

Types

type BlockReader

type BlockReader struct {
	// contains filtered or unexported fields
}

func NewBlockReader

func NewBlockReader() *BlockReader

func (*BlockReader) Close

func (r *BlockReader) Close() error

func (*BlockReader) Enqueue

func (r *BlockReader) Enqueue(data []byte)

func (*BlockReader) Read

func (r *BlockReader) Read(into []byte) (int, error)

func (*BlockReader) TryRead

func (r *BlockReader) TryRead(into []byte) (bool, int, error)

type Client

type Client interface {
	Configure(compression CompressionMethod) error
	Close() error
	Write(*Frame) error
	NewStream() (Stream, error)
	Terminate(reason ErrorCode) error
}

func NewClient

func NewClient(conn io.ReadWriteCloser) Client

type CompressionMethod

type CompressionMethod int
const (
	CompressionMethodNone CompressionMethod = iota
	CompressionMethodGzip
)

func (CompressionMethod) Compress

func (c CompressionMethod) Compress(buf []byte) []byte

func (CompressionMethod) Decompress

func (c CompressionMethod) Decompress(data []byte) ([]byte, error)

func (CompressionMethod) String

func (i CompressionMethod) String() string

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn represents a single active connection to a server

func NewConn

func NewConn(s server, id int, io io.ReadWriteCloser) *Conn

func (*Conn) Write

func (c *Conn) Write(fr *Frame) error

type ConnectionResetError

type ConnectionResetError struct {
	Reason  ErrorCode
	Details string
}

func (*ConnectionResetError) Error

func (c *ConnectionResetError) Error() string

type DataFrame

type DataFrame struct {
	StreamID uint32

	EndData   bool
	EndStream bool

	Payload []byte
}

func (*DataFrame) FrameKind

func (*DataFrame) FrameKind() FrameKind

func (*DataFrame) FromFrame

func (d *DataFrame) FromFrame(f *Frame) error

func (*DataFrame) IntoFrame

func (d *DataFrame) IntoFrame() *Frame

type ErrorCode

type ErrorCode uint32
const (
	ErrorCodeNoError            ErrorCode = 0x00
	ErrorCodeProtocolError      ErrorCode = 0x01
	ErrorCodeInternalError      ErrorCode = 0x02
	ErrorCodeStreamClosed       ErrorCode = 0x03
	ErrorCodeFrameSizeError     ErrorCode = 0x04
	ErrorCodeRefusedStream      ErrorCode = 0x05
	ErrorCodeCancel             ErrorCode = 0x06
	ErrorCodeCompressionError   ErrorCode = 0x07
	ErrorCodeEnhanceYourCalm    ErrorCode = 0x08
	ErrorCodeInadequateSecurity ErrorCode = 0x09
)

func (ErrorCode) String

func (e ErrorCode) String() string

type FairMutex

type FairMutex struct {
	// contains filtered or unexported fields
}

func NewFairMutex

func NewFairMutex() *FairMutex

func (*FairMutex) Lock

func (m *FairMutex) Lock()

func (*FairMutex) Unlock

func (m *FairMutex) Unlock()

type Frame

type Frame struct {
	StreamID  uint32
	FrameKind FrameKind
	Flags     uint8
	Length    uint16
	Payload   []byte
}

func (*Frame) Bytes

func (f *Frame) Bytes(method CompressionMethod) []byte

func (*Frame) Decompress

func (f *Frame) Decompress(method CompressionMethod) (err error)

func (*Frame) ValidateKind

func (f *Frame) ValidateKind(expected FrameKind, associated bool) error

func (*Frame) ValidateSize

func (f *Frame) ValidateSize(s int) error

type FrameKind

type FrameKind uint8
const (
	FrameKindHello       FrameKind = 0x00
	FrameKindPing        FrameKind = 0x01
	FrameKindGoAway      FrameKind = 0x02
	FrameKindMakeStream  FrameKind = 0x03
	FrameKindResetStream FrameKind = 0x04
	FrameKindData        FrameKind = 0x05
)

func (FrameKind) String

func (k FrameKind) String() string

type FrameReader

type FrameReader struct {
	// contains filtered or unexported fields
}

func NewFrameReader

func NewFrameReader(r io.Reader) *FrameReader

func (*FrameReader) Read

func (f *FrameReader) Read() (*Frame, error)

type FrameTypeMismatchError

type FrameTypeMismatchError struct {
	Expected, Received FrameKind
}

func (*FrameTypeMismatchError) Error

func (f *FrameTypeMismatchError) Error() string

type Framer

type Framer interface {
	IntoFrame() *Frame
	FromFrame(f *Frame) error
	FrameKind() FrameKind
}

func DataFramesFromBuffer

func DataFramesFromBuffer(streamID uint32, endStream bool, buffer []byte) []Framer

type GoAwayFrame

type GoAwayFrame struct {
	LastStreamID   uint32
	ErrorCode      ErrorCode
	AdditionalData []byte
}

func (*GoAwayFrame) FrameKind

func (*GoAwayFrame) FrameKind() FrameKind

func (*GoAwayFrame) FromFrame

func (g *GoAwayFrame) FromFrame(f *Frame) error

func (*GoAwayFrame) IntoFrame

func (g *GoAwayFrame) IntoFrame() *Frame

type HelloFrame

type HelloFrame struct {
	Ack             bool
	CompressionGZip bool

	MaxConcurrentStreams uint32
}

func (*HelloFrame) FrameKind

func (*HelloFrame) FrameKind() FrameKind

func (*HelloFrame) FromFrame

func (s *HelloFrame) FromFrame(f *Frame) error

func (*HelloFrame) IntoFrame

func (s *HelloFrame) IntoFrame() *Frame

type InvalidFrameError

type InvalidFrameError struct {
	// contains filtered or unexported fields
}

func (*InvalidFrameError) Error

func (i *InvalidFrameError) Error() string

type InvalidFrameLengthError

type InvalidFrameLengthError struct {
	// contains filtered or unexported fields
}

func (*InvalidFrameLengthError) Error

func (i *InvalidFrameLengthError) Error() string

type MakeStreamFrame

type MakeStreamFrame struct {
	StreamID uint32
}

func (*MakeStreamFrame) FrameKind

func (*MakeStreamFrame) FrameKind() FrameKind

func (*MakeStreamFrame) FromFrame

func (r *MakeStreamFrame) FromFrame(f *Frame) error

func (*MakeStreamFrame) IntoFrame

func (r *MakeStreamFrame) IntoFrame() *Frame

type PingFrame

type PingFrame struct {
	Ack     bool
	Payload []byte
}

func (*PingFrame) FrameKind

func (*PingFrame) FrameKind() FrameKind

func (*PingFrame) FromFrame

func (p *PingFrame) FromFrame(f *Frame) error

func (*PingFrame) IntoFrame

func (p *PingFrame) IntoFrame() *Frame

type ResetStreamFrame

type ResetStreamFrame struct {
	StreamID  uint32
	ErrorCode ErrorCode
}

func (*ResetStreamFrame) FrameKind

func (*ResetStreamFrame) FrameKind() FrameKind

func (*ResetStreamFrame) FromFrame

func (r *ResetStreamFrame) FromFrame(f *Frame) error

func (*ResetStreamFrame) IntoFrame

func (r *ResetStreamFrame) IntoFrame() *Frame

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(l net.Listener, handler StreamHandler) *Server

func (*Server) CancelStream

func (s *Server) CancelStream(stream Stream)

func (*Server) Serve

func (s *Server) Serve() error

func (*Server) ServiceStream

func (s *Server) ServiceStream(stream Stream)

func (*Server) Shutdown

func (s *Server) Shutdown() error

type Stream

type Stream interface {
	io.Reader

	Write(data []byte, endStream bool) error
	Reset(code ErrorCode) error
	CloseLocal() error
	ID() uint32
	SetExternalID(string)
	ExternalID() string
	// contains filtered or unexported methods
}

func NewStream

func NewStream(id uint32, c conn) Stream

type StreamCanceledError

type StreamCanceledError struct {
	Reason ErrorCode
}

func (*StreamCanceledError) Error

func (c *StreamCanceledError) Error() string

type StreamHandler

type StreamHandler interface {
	ServiceStream(stream Stream)
	CancelStream(stream Stream)
}

type StreamResetError

type StreamResetError struct {
	Reason ErrorCode
}

func (*StreamResetError) Error

func (c *StreamResetError) Error() string

type UnexpectedAssociatedFrameError

type UnexpectedAssociatedFrameError struct {
	Kind FrameKind
}

func (*UnexpectedAssociatedFrameError) Error

type UnexpectedUnassociatedFrameError

type UnexpectedUnassociatedFrameError struct {
	Kind FrameKind
}

func (*UnexpectedUnassociatedFrameError) Error

type UnknownFrameKindError

type UnknownFrameKindError struct {
	ReceivedKind byte
}

func (*UnknownFrameKindError) Error

func (e *UnknownFrameKindError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL