mode

package
v0.0.0-...-ecf2efd Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInterfaceIsNil        = errors.New("interface is nil")
	ErrModeNotSupported      = errors.New("mode is not supported")
	ErrAmbiguousModeAnnounce = errors.New("ambiguous mode announce, expected other byte sequence")
)

Functions

This section is empty.

Types

type ErrNotMultiple

type ErrNotMultiple struct {
	Len int
}

func (ErrNotMultiple) Error

func (e ErrNotMultiple) Error() string

type Mode

type Mode interface {
	WriteMsg([]byte) error // this is not same as the io.Writer
	ReadMsg() ([]byte, error)
	// contains filtered or unexported methods
}

Mode is an interface which handles many ways as the connection sides must determine the size of the transmitted messages. Unlike HTTP or UDP connections, raw TCP connections, as well as WebSockets doesn't have a standard way to determine the size of the transmitted or received message: their main purpose is just to transmit bytes with right order. Mode allows the sides of the connection don't analyze traffic or use any end message sequence. In fact, in MTProto world, Mode works like microprotocol, which is packaging messages in the container that announces its size in advance

func Detect

func Detect(conn io.ReadWriter) (Mode, error)

Detect detects mode based on first byte sequence returned from conn

func New

func New(v Variant, conn io.ReadWriter) (Mode, error)

type Variant

type Variant uint8
const (
	Abridged Variant = iota
	Intermediate
	PaddedIntermediate
	Full
)

func GetVariant

func GetVariant(m Mode) (Variant, error)

Jump to

Keyboard shortcuts

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