codec

package
v0.0.0-...-f756a1e Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package codec contains MTProto transport encoding implementations.

See https://core.telegram.org/mtproto/mtproto-transports

Index

Constants

View Source
const (
	// CodeAuthKeyNotFound means that specified auth key ID cannot be found by the DC.
	// Also, may be returned during key exchange.
	CodeAuthKeyNotFound = 404

	// CodeWrongDC means that current DC is wrong.
	// Usually returned by server when key exchange sends wrong DC ID.
	CodeWrongDC = 444

	// CodeTransportFlood means that too many transport connections are
	// established to the same IP in a too short lapse of time, or if any
	// of the container/service message limits are reached.
	CodeTransportFlood = 429
)

Variables

View Source
var AbridgedClientStart = [1]byte{0xef}

AbridgedClientStart is starting bytes sent by client in Abridged mode.

Note that server does not respond with it.

View Source
var ErrProtocolHeaderMismatch = errors.New("protocol header mismatch")

ErrProtocolHeaderMismatch means that received protocol header is mismatched with expected.

View Source
var IntermediateClientStart = [4]byte{0xee, 0xee, 0xee, 0xee}

IntermediateClientStart is starting bytes sent by client in Intermediate mode.

Note that server does not respond with it.

View Source
var PaddedIntermediateClientStart = [4]byte{0xdd, 0xdd, 0xdd, 0xdd}

PaddedIntermediateClientStart is starting bytes sent by client in Padded intermediate mode.

Note that server does not respond with it.

Functions

This section is empty.

Types

type Abridged

type Abridged struct{}

Abridged is intermediate MTProto transport.

See https://core.telegram.org/mtproto/mtproto-transports#abridged

func (Abridged) ObfuscatedTag

func (i Abridged) ObfuscatedTag() (r [4]byte)

ObfuscatedTag returns protocol tag for obfuscation.

func (Abridged) Read

func (i Abridged) Read(r io.Reader, b *bin.Buffer) error

Read fills buffer with received message.

func (Abridged) ReadHeader

func (i Abridged) ReadHeader(r io.Reader) error

ReadHeader reads protocol tag.

func (Abridged) Write

func (i Abridged) Write(w io.Writer, b *bin.Buffer) error

Write encode to writer message from given buffer.

func (Abridged) WriteHeader

func (i Abridged) WriteHeader(w io.Writer) error

WriteHeader sends protocol tag.

type Codec

type Codec interface {
	// WriteHeader sends protocol tag if needed.
	WriteHeader(w io.Writer) error
	// ReadHeader reads protocol tag if needed.
	ReadHeader(r io.Reader) error
	// Write encode to writer message from given buffer.
	Write(w io.Writer, b *bin.Buffer) error
	// Read fills buffer with received message.
	Read(r io.Reader, b *bin.Buffer) error
}

Codec is MTProto transport protocol encoding abstraction.

type Full

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

Full is full MTProto transport.

See https://core.telegram.org/mtproto/mtproto-transports#full

func (*Full) Read

func (i *Full) Read(r io.Reader, b *bin.Buffer) error

Read fills buffer with received message.

func (*Full) ReadHeader

func (i *Full) ReadHeader(r io.Reader) (err error)

ReadHeader reads protocol tag.

func (*Full) Write

func (i *Full) Write(w io.Writer, b *bin.Buffer) error

Write encode to writer message from given buffer.

func (*Full) WriteHeader

func (i *Full) WriteHeader(w io.Writer) (err error)

WriteHeader sends protocol tag.

type Intermediate

type Intermediate struct{}

Intermediate is intermediate MTProto transport.

See https://core.telegram.org/mtproto/mtproto-transports#intermediate

func (Intermediate) ObfuscatedTag

func (i Intermediate) ObfuscatedTag() [4]byte

ObfuscatedTag returns protocol tag for obfuscation.

func (Intermediate) Read

func (i Intermediate) Read(r io.Reader, b *bin.Buffer) error

Read fills buffer with received message.

func (Intermediate) ReadHeader

func (i Intermediate) ReadHeader(r io.Reader) (err error)

ReadHeader reads protocol tag.

func (Intermediate) Write

func (i Intermediate) Write(w io.Writer, b *bin.Buffer) error

Write encode to writer message from given buffer.

func (Intermediate) WriteHeader

func (i Intermediate) WriteHeader(w io.Writer) (err error)

WriteHeader sends protocol tag.

type NoHeader

type NoHeader struct {
	Codec
}

NoHeader wraps codec to skip WriteHeader.

func (NoHeader) ReadHeader

func (NoHeader) ReadHeader(io.Reader) error

ReadHeader implements Codec.

func (NoHeader) WriteHeader

func (NoHeader) WriteHeader(io.Writer) error

WriteHeader implements Codec.

type PaddedIntermediate

type PaddedIntermediate struct{}

PaddedIntermediate is intermediate MTProto transport.

See https://core.telegram.org/mtproto/mtproto-transports#padded-intermediate

func (PaddedIntermediate) ObfuscatedTag

func (i PaddedIntermediate) ObfuscatedTag() [4]byte

ObfuscatedTag returns protocol tag for obfuscation.

func (PaddedIntermediate) Read

func (i PaddedIntermediate) Read(r io.Reader, b *bin.Buffer) error

Read fills buffer with received message.

func (PaddedIntermediate) ReadHeader

func (i PaddedIntermediate) ReadHeader(r io.Reader) error

ReadHeader reads protocol tag.

func (PaddedIntermediate) Write

func (i PaddedIntermediate) Write(w io.Writer, b *bin.Buffer) error

Write encode to writer message from given buffer.

func (PaddedIntermediate) WriteHeader

func (i PaddedIntermediate) WriteHeader(w io.Writer) error

WriteHeader sends protocol tag.

type ProtocolErr

type ProtocolErr struct {
	Code int32
}

ProtocolErr represents protocol level error.

func (ProtocolErr) Error

func (p ProtocolErr) Error() string

type TaggedCodec

type TaggedCodec interface {
	Codec
	// ObfuscatedTag returns protocol tag for obfuscation.
	ObfuscatedTag() [4]byte
}

TaggedCodec is codec with protocol tag.

Jump to

Keyboard shortcuts

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