Documentation
¶
Index ¶
- Constants
- Variables
- func EncodeRequestType(tp string) string
- func GetArgumentCount(desc string) int
- func HeadGetDefault(headers api.HeaderMap, key string, defaultValue string) string
- func Matcher(data []byte) api.MatchResult
- type DubboProtocol
- func (proto DubboProtocol) Decode(ctx context.Context, data api.IoBuffer) (interface{}, error)
- func (proto DubboProtocol) EnableWorkerPool() bool
- func (proto DubboProtocol) Encode(ctx context.Context, model interface{}) (api.IoBuffer, error)
- func (proto DubboProtocol) GenerateRequestID(streamID *uint64) uint64
- func (proto DubboProtocol) Hijack(ctx context.Context, request api.XFrame, statusCode uint32) api.XRespFrame
- func (proto DubboProtocol) Mapping(httpStatusCode uint32) uint32
- func (proto DubboProtocol) Name() api.ProtocolName
- func (proto DubboProtocol) PoolMode() api.PoolMode
- func (proto DubboProtocol) Reply(ctx context.Context, request api.XFrame) api.XRespFrame
- func (proto DubboProtocol) Trigger(ctx context.Context, requestId uint64) api.XFrame
- type Frame
- func (r *Frame) Clone() api.HeaderMap
- func (r *Frame) GetData() api.IoBuffer
- func (r *Frame) GetHeader() api.HeaderMap
- func (r *Frame) GetRequestId() uint64
- func (r *Frame) GetStatusCode() uint32
- func (r *Frame) GetStreamType() api.StreamType
- func (r *Frame) GetTimeout() int32
- func (r *Frame) IsHeartbeatFrame() bool
- func (r *Frame) SetData(data api.IoBuffer)
- func (r *Frame) SetRequestId(id uint64)
- type Header
- type Parameter
- type StatusMapping
Constants ¶
const ( HeaderLen = 16 IdLen = 8 MagicIdx = 0 FlagIdx = 2 StatusIdx = 3 IdIdx = 4 DataLenIdx = 12 DataLenSize = 4 )
dubbo protocol
const ( CmdTypeResponse byte = 0 // cmd type CmdTypeRequest byte = 1 CmdTypeRequestOneway byte = 2 UnKnownCmdType string = "unknown cmd type" )
req/resp type
const ( RespStatusOK = 20 RespStatusClientTimeout = 30 RespStatusServerTimeout = 31 RespStatusBadRequest = 40 RespStatusBadResponse = 50 RespStatusServiceNotFound = 60 RespStatusServiceError = 70 RespStatusServerError = 80 RespStatusClientError = 90 RespStatusServerThreadpoolExhaustedError = 100 )
* https://dubbo.apache.org/zh/docs/v2.7/dev/implementation/#%E8%BF%9C%E7%A8%8B%E9%80%9A%E8%AE%AF%E7%BB%86%E8%8A%82 * 20 - OK * 30 - CLIENT_TIMEOUT * 31 - SERVER_TIMEOUT * 40 - BAD_REQUEST * 50 - BAD_RESPONSE * 60 - SERVICE_NOT_FOUND * 70 - SERVICE_ERROR * 80 - SERVER_ERROR * 90 - CLIENT_ERROR * 100 - SERVER_THREADPOOL_EXHAUSTED_ERROR
const ( EventRequest int = 1 // request EventResponse int = 0 // response )
const ( FrameworkVersionNameHeader string = "dubbo" ServiceNameHeader string = "service" MethodNameHeader string = "method" VersionNameHeader string = "version" GroupNameHeader string = "group" InterfaceNameHeader string = "interface" )
const ( EgressDubbo string = "egress_dubbo" IngressDubbo string = "ingress_dubbo" )
const ( RESPONSE_WITH_EXCEPTION = 0 RESPONSE_VALUE = 1 RESPONSE_NULL_VALUE = 2 RESPONSE_WITH_EXCEPTION_WITH_ATTACHMENTS = 3 RESPONSE_VALUE_WITH_ATTACHMENTS = 4 RESPONSE_NULL_VALUE_WITH_ATTACHMENTS = 5 )
dubbo response code
const (
ProtocolName = "dubbo"
)
const (
ResponseStatusSuccess uint16 = 0x14 // 0x14 response status
)
Variables ¶
var MagicTag = []byte{0xda, 0xbb}
* * https://dubbo.apache.org/zh/docs/v2.7/dev/implementation/#%E8%BF%9C%E7%A8%8B%E9%80%9A%E8%AE%AF%E7%BB%86%E8%8A%82 * Dubbo protocol * Request & Response: (byte) * 0 1 2 3 4 5 6 7 8 * +-----------+-----------+-----------+-----------+-----------------------------------------------+ * |magic high | magic low | flag | status | id | * +-----------+-----------+----+------+-----------------------------------------------------------+ * | id | | data length | * +-----------------------------------------------+-----------------------------------------------+ * | | payload | * +-----------------------------------------------------------------------------------------------+ * magic: 0xdabb | * | * | * +--------------------------+ * | * v * flag: (bit offset) * 8 7 6 5 4 3 2 1 0 * +-----------+-----------+-----------+-----------------------------------------------------------+ * | req/rsp | two way | event | serialization id | * +-----------+-----------+-----------+-----------------------------------------------------------+ * event: 1 mean ping * two way: 1 mean req & rsp pair * req/rsp: 1 mean req
Functions ¶
func EncodeRequestType ¶
func GetArgumentCount ¶
more unit test:
https://github.com/zonghaishang/dubbo/commit/e0fd702825a274379fb609229bdb06ca0586122e
func HeadGetDefault ¶
func Matcher ¶
func Matcher(data []byte) api.MatchResult
predicate dubbo header len and compare magic number
Types ¶
type DubboProtocol ¶
type DubboProtocol struct{}
func (DubboProtocol) EnableWorkerPool ¶
func (proto DubboProtocol) EnableWorkerPool() bool
func (DubboProtocol) GenerateRequestID ¶
func (proto DubboProtocol) GenerateRequestID(streamID *uint64) uint64
func (DubboProtocol) Hijack ¶
func (proto DubboProtocol) Hijack(ctx context.Context, request api.XFrame, statusCode uint32) api.XRespFrame
func (DubboProtocol) Mapping ¶
func (proto DubboProtocol) Mapping(httpStatusCode uint32) uint32
func (DubboProtocol) Name ¶
func (proto DubboProtocol) Name() api.ProtocolName
func (DubboProtocol) PoolMode ¶
func (proto DubboProtocol) PoolMode() api.PoolMode
PoolMode returns whether pingpong or multiplex
func (DubboProtocol) Reply ¶
func (proto DubboProtocol) Reply(ctx context.Context, request api.XFrame) api.XRespFrame
type Frame ¶
type Frame struct { Header // contains filtered or unexported fields }
func NewRpcRequest ¶
NewRpcRequest is a utility function which build rpc Request object of bolt protocol.
func NewRpcResponse ¶
NewRpcResponse is a utility function which build rpc Response object of bolt protocol.
func (*Frame) GetStatusCode ¶
func (*Frame) GetStreamType ¶
func (r *Frame) GetStreamType() api.StreamType
func (*Frame) GetTimeout ¶
dubbo frame returns default timeout TODO: use dubbo timeout?
func (*Frame) IsHeartbeatFrame ¶
func (*Frame) SetRequestId ¶
type Header ¶
type Header struct { Magic []byte Flag byte Status byte Id uint64 DataLen uint32 IsEvent bool // true: heartbeat or readonly event IsTwoWay bool // true: send request and expect response, false: just request without response Direction int // 1 mean req SerializationId int // 2 mean hessian common.Header }
type Parameter ¶
type Parameter struct { Type string `json:"type"` Value interface{} `json:"value"` }