Documentation
¶
Overview ¶
Package frame defines frames for yomo.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrReservedTag = errors.New("[0xF000, 0xFFFF] is reserved; please do not write within this range")
ErrReservedTag is returned when write a reserved tag.
Functions ¶
func IsReservedTag ¶ added in v1.18.8
IsReservedTag returns error when write a reserved tag.
Types ¶
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.
type ErrConnClosed ¶ added in v1.16.6
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:
- HandshakeFrame
- HandshakeAckFrame
- DataFrame
- RejectedFrame
- GoawayFrame
- ConnectToFrame
Read frame comments to understand the role of the frame.
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 // FunctionDefinition is the definition of the AI function. FunctionDefinition []byte // 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 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. )