frame

package
v1.18.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: Apache-2.0 Imports: 4 Imported by: 3

Documentation

Overview

Package frame defines frames for yomo.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AIRegisterFunctionAckFrame added in v1.18.0

type AIRegisterFunctionAckFrame struct {
	Name string
	Tag  uint32
}

AIRegisterFunctionAckFrame is used to ack AIRegisterFunctionFrame.

func (*AIRegisterFunctionAckFrame) Type added in v1.18.0

func (f *AIRegisterFunctionAckFrame) Type() Type

Type returns the type of AIRegisterFunctionAckFrame.

type AIRegisterFunctionFrame added in v1.18.0

type AIRegisterFunctionFrame struct {
	Name       string // Name is the name of the AI function.
	Tag        uint32
	Definition []byte // Definition is the definition of the AI function.
}

AIRegisterFunctionFrame is used to register AI function.

func (*AIRegisterFunctionFrame) Type added in v1.18.0

func (f *AIRegisterFunctionFrame) Type() Type

Type returns the type of AIRegisterFunctionFrame.

type Codec added in v1.13.1

type Codec interface {
	// Decode decodes byte array to frame.
	Decode([]byte, Frame) error
	// Encode encodes frame to byte array.
	Encode(Frame) ([]byte, error)
}

Codec encodes and decodes byte array to frame.

type Conn added in v1.16.5

type Conn interface {
	// Context returns Conn.Context.
	// The Context can be used to manage the lifecycle of connection and
	// retrieve error using `context.Cause(conn.Context())` after calling `CloseWithError()`.
	Context() context.Context
	// WriteFrame writes a frame to connection.
	WriteFrame(Frame) error
	// ReadFrame returns a channel from which frames can be received.
	ReadFrame() (Frame, error)
	// RemoteAddr returns the remote address of connection.
	RemoteAddr() net.Addr
	// LocalAddr returns the local address of connection.
	LocalAddr() net.Addr
	// CloseWithError closes the connection with an error message.
	// It will be unavailable if the connection is closed. the error message should be written to the conn.Context().
	CloseWithError(string) error
}

Conn is a connection that transmits data in frame format.

type ConnectToFrame added in v1.17.2

type ConnectToFrame struct {
	// Endpoint is the new endpoint that will be connected by client.
	Endpoint string
}

ConnectToFrame is is used by server to notify client to connect a new endpoint.

func (*ConnectToFrame) Type added in v1.17.2

func (f *ConnectToFrame) Type() Type

Type returns the type of ConnectToFrame.

type DataFrame

type DataFrame struct {
	// Metadata stores additional data beyond the Payload,
	// it is an map[string]string{} that be encoded in msgpack.
	Metadata []byte
	// Tag is used for data router.
	Tag Tag
	// Payload is the data to transmit.
	Payload []byte
}

DataFrame carries tagged data to transmit across connection.

func (*DataFrame) Type

func (f *DataFrame) Type() Type

Type returns the type of DataFrame.

type ErrConnClosed added in v1.16.6

type ErrConnClosed struct {
	Remote       bool
	ErrorMessage string
}

ErrConnClosed is returned when the connection be closed by remote or local. The ReadFrame() and WriteFrame() should return this error after calling CloseWithError().

func NewErrConnClosed added in v1.16.6

func NewErrConnClosed(remote bool, errMsg string) *ErrConnClosed

NewErrConnClosed returns an ErrConnClosed.

func (*ErrConnClosed) Error added in v1.16.6

func (e *ErrConnClosed) Error() string

Error implements the error interface and returns the reason why the connection was closed.

type Frame

type Frame interface {
	// Type returns the type of frame.
	Type() Type
}

Frame is the minimum unit required for Yomo to run. Yomo transmits various instructions and data through the frames.

following frame types are supported by Yomo:

  1. HandshakeFrame
  2. HandshakeAckFrame
  3. DataFrame
  4. RejectedFrame
  5. GoawayFrame
  6. ConnectToFrame
  7. AIRegisterFunctionFrame
  8. AIRegisterFunctionAckFrame

Read frame comments to understand the role of the frame.

func NewFrame added in v1.13.1

func NewFrame(f Type) (Frame, error)

NewFrame creates a new frame from Type.

type GoawayFrame added in v1.7.3

type GoawayFrame struct {
	// Message contains the reason why the connection be evicted.
	Message string
}

GoawayFrame is is used by server to evict a connection.

func (*GoawayFrame) Type added in v1.7.3

func (f *GoawayFrame) Type() Type

Type returns the type of GoawayFrame.

type HandshakeAckFrame added in v1.10.0

type HandshakeAckFrame struct{}

HandshakeAckFrame is used to ack handshake, If handshake successful, The server will send HandshakeAckFrame to the client.

func (*HandshakeAckFrame) Type added in v1.10.0

func (f *HandshakeAckFrame) Type() Type

Type returns the type of HandshakeAckFrame.

type HandshakeFrame

type HandshakeFrame struct {
	// Name is the name of the connection that will be created.
	Name string
	// ID is the ID of the connection that will be created.
	ID string
	// ClientType is the type of client.
	ClientType byte
	// ObserveDataTags is the ObserveDataTags of the connection that will be created.
	ObserveDataTags []Tag
	// AuthName is the authentication name.
	AuthName string
	// AuthPayload is the authentication payload.
	AuthPayload string
	// Version is used by the source/sfn to communicate their spec version to the server.
	Version string
	// WantedTarget represents the target that accepts the data frames that carrying the same target.
	WantedTarget string
}

The HandshakeFrame is the frame through which the client obtains a new connection from the server. It includes essential details required for the creation of a fresh connection. The server then generates the connection utilizing this provided information.

func (*HandshakeFrame) Type

func (f *HandshakeFrame) Type() Type

Type returns the type of HandshakeFrame.

type Listener added in v1.16.5

type Listener interface {
	// Accept accepts Conns.
	Accept(context.Context) (Conn, error)
	// Close closes listener,
	// If listener be closed, all Conn accepted will be unavailable.
	Close() error
}

Listener accepts Conns.

type PacketReadWriter added in v1.13.1

type PacketReadWriter interface {
	ReadPacket(io.Reader) (Type, []byte, error)
	WritePacket(io.Writer, Type, []byte) error
}

PacketReadWriter reads packets from the io.Reader and writes packets to the io.Writer. If read failed, return the frameType, the data of the packet and an error.

type RejectedFrame

type RejectedFrame struct {
	// Message encapsulates the rationale behind the rejection of the request.
	Message string
}

RejectedFrame is used to reject a client request.

func (*RejectedFrame) Type

func (f *RejectedFrame) Type() Type

Type returns the type of RejectedFrame.

type Tag added in v1.10.0

type Tag = uint32

Tag tags data and can be used for data routing.

type Type

type Type byte

Type defined The type of frame.

const (
	TypeDataFrame                  Type = 0x3F // TypeDataFrame is the type of DataFrame.
	TypeHandshakeFrame             Type = 0x31 // TypeHandshakeFrame is the type of HandshakeFrame.
	TypeHandshakeAckFrame          Type = 0x29 // TypeHandshakeAckFrame is the type of HandshakeAckFrame.
	TypeRejectedFrame              Type = 0x39 // TypeRejectedFrame is the type of RejectedFrame.
	TypeGoawayFrame                Type = 0x2E // TypeGoawayFrame is the type of GoawayFrame.
	TypeConnectToFrame             Type = 0x3E // TypeConnectToFrame is the type of ConnectToFrame.
	TypeAIRegisterFunctionFrame    Type = 0x10 // TypeAIRegisterFunctionFrame is the type of AIRegisterFunctionFrame.
	TypeAIRegisterFunctionAckFrame Type = 0x11 // TypeAIRegisterFunctionAckFrame is the type of AIRegisterFunctionAckFrame.

)

func (Type) String

func (f Type) String() string

String returns a human-readable string which represents the frame type. The string can be used for debugging or logging purposes.

type Writer added in v1.10.0

type Writer interface {
	// WriteFrame writes frame to underlying connection.
	WriteFrame(Frame) error
}

Writer is the interface that wraps the WriteFrame method, it writes frame to the underlying connection.

Jump to

Keyboard shortcuts

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