protocol

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: Apache-2.0 Imports: 9 Imported by: 32

Documentation

Index

Constants

View Source
const (
	Auto      api.Protocol = "Auto"
	SofaRPC   api.Protocol = "SofaRpc"
	HTTP1     api.Protocol = "Http1"
	HTTP2     api.Protocol = "Http2"
	Xprotocol api.Protocol = "X"
)

ProtocolName type definition

View Source
const (
	Request  = "Request"
	Response = "Response"
)

header direction definition

Variables

View Source
var (
	ErrNotFound = errors.New("no convert function found for given protocol pair")

	ErrHeaderDirection = errors.New("no header direction info")
)
View Source
var (
	ErrNoMapping = errors.New("no mapping function found")
)

Functions

func ConvertData

func ConvertData(ctx context.Context, src, dst api.Protocol, srcData buffer.IoBuffer) (buffer.IoBuffer, error)

ConvertData convert data from source protocol format to destination protocol format

func ConvertHeader

func ConvertHeader(ctx context.Context, src, dst api.Protocol, srcHeader api.HeaderMap) (api.HeaderMap, error)

ConvertHeader convert header from source protocol format to destination protocol format

func ConvertTrailer

func ConvertTrailer(ctx context.Context, src, dst api.Protocol, srcTrailer api.HeaderMap) (api.HeaderMap, error)

ConvertTrailer convert trailer from source protocol format to destination protocol format

func GenerateID

func GenerateID() uint64

GenerateID get id by default global generator

func GenerateIDString

func GenerateIDString() string

GenerateIDString get id string by default global generator

func MappingHeaderStatusCode

func MappingHeaderStatusCode(ctx context.Context, p api.Protocol, headers api.HeaderMap) (int, error)

func RegisterCommonConv

func RegisterCommonConv(protocol api.Protocol, from, to ProtocolConv)

RegisterCommonConv register concrete protocol convert function for specified protocol and common representation. e.g. SofaRpcCmd <-> CommonHeader, which both implements the types.HeaderMap interface

func RegisterConv

func RegisterConv(src, dst api.Protocol, f ProtocolConv)

RegisterConv register concrete protocol convert function for specified source protocol and destination protocol

func RegisterMapping

func RegisterMapping(p api.Protocol, m HTTPMapping)

func RequestIDConv

func RequestIDConv(streamID string) uint64

RequestIDConv convert streamID from string to uint64

func StreamIDConv

func StreamIDConv(streamID uint64) string

StreamIDConv convert streamID from uint64 to string

Types

type CommonHeader

type CommonHeader map[string]string

CommonHeader wrapper for map[string]string

func (CommonHeader) Add

func (h CommonHeader) Add(key string, value string)

Add value for given key. Multiple headers with the same key may be added with this function. Use Set for setting a single header for the given key.

func (CommonHeader) ByteSize

func (h CommonHeader) ByteSize() uint64

func (CommonHeader) Clone

func (h CommonHeader) Clone() api.HeaderMap

Clone used to deep copy header's map

func (CommonHeader) Del

func (h CommonHeader) Del(key string)

Del delete pair of specified key

func (CommonHeader) Get

func (h CommonHeader) Get(key string) (value string, ok bool)

Get value of key

func (CommonHeader) Range

func (h CommonHeader) Range(f func(key, value string) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

func (CommonHeader) Set

func (h CommonHeader) Set(key string, value string)

Set key-value pair in header map, the previous pair will be replaced if exists

type HTTPMapping

type HTTPMapping interface {
	MappingHeaderStatusCode(ctx context.Context, headers api.HeaderMap) (int, error)
}

HTTPMapping maps the contents of protocols to HTTP standard

type IDGenerator

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

IDGenerator utility to generate auto-increment ids

func (*IDGenerator) Get

func (g *IDGenerator) Get() uint64

Get get id

func (*IDGenerator) GetString

func (g *IDGenerator) GetString() string

Get get id in string format

type ProtocolBuffers

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

func ProtocolBuffersByContext

func ProtocolBuffersByContext(ctx context.Context) *ProtocolBuffers

ProtocolBuffersByContext returns ProtocolBuffers by context

func (*ProtocolBuffers) GetReqData

func (p *ProtocolBuffers) GetReqData(size int) buffer.IoBuffer

GetReqData returns IoBuffer for request data

func (*ProtocolBuffers) GetReqHeader

func (p *ProtocolBuffers) GetReqHeader(size int) buffer.IoBuffer

GetReqHeader returns IoBuffer for request header

func (*ProtocolBuffers) GetReqHeaders

func (p *ProtocolBuffers) GetReqHeaders() map[string]string

GetReqHeaders returns map for request header

func (*ProtocolBuffers) GetReqTailers

func (p *ProtocolBuffers) GetReqTailers() map[string]string

GetReqTailers returns map for request tailers

func (*ProtocolBuffers) GetRspData

func (p *ProtocolBuffers) GetRspData(size int) buffer.IoBuffer

GetRspData returns IoBuffer for response data

func (*ProtocolBuffers) GetRspHeader

func (p *ProtocolBuffers) GetRspHeader(size int) buffer.IoBuffer

GetRspHeader returns IoBuffer for response header

func (*ProtocolBuffers) GetRspHeaders

func (p *ProtocolBuffers) GetRspHeaders() map[string]string

GetRspHeaders returns map for response header

func (*ProtocolBuffers) GetRspTailers

func (p *ProtocolBuffers) GetRspTailers() map[string]string

GetRspTailers returns IoBuffer for response tailers

type ProtocolConv

type ProtocolConv interface {
	// ConvHeader convert header part represents in `api.HeaderMap`
	ConvHeader(ctx context.Context, headerMap api.HeaderMap) (api.HeaderMap, error)

	// ConvData convert data part represents in `buffer.IoBuffer`
	ConvData(ctx context.Context, buffer buffer.IoBuffer) (buffer.IoBuffer, error)

	// ConvTrailer convert trailer part represents in `api.HeaderMap`
	ConvTrailer(ctx context.Context, headerMap api.HeaderMap) (api.HeaderMap, error)
}

ProtocolConv extract common methods for protocol conversion(header, data, trailer)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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