You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.2 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package response
import (
protocolpkg "github.com/noahlann/nnet/pkg/protocol"
)
// Response 响应接口
// 写入的数据会自动编码和协议封装
type Response interface {
// Write 写入数据自动resolve codec进行编码和协议封装
// data: Go对象struct、map等会自动通过resolver解析codec进行编码
Write(data interface{}) error
// WriteString 写入字符串数据(快捷方法)
WriteString(data string) error
// WriteWithCodec 使用指定的编解码器写入数据手动选择codec
// data: Go对象struct、map等
// codecName: 编解码器名称
WriteWithCodec(data interface{}, codecName string) error
// WriteBytes 写入原始字节(不进行编码,但会进行协议封装)
// 主要用于需要手动控制编码的场景
WriteBytes(data []byte) error
// Header 获取协议帧头(可以设置响应帧头)
Header() protocolpkg.FrameHeader
// SetHeader 设置协议帧头(如果有)
SetHeader(header protocolpkg.FrameHeader)
// Protocol 获取协议信息
Protocol() protocolpkg.Protocol
}
// FrameHeader 协议帧头接口类型别名统一使用protocol.FrameHeader
type FrameHeader = protocolpkg.FrameHeader