protocol

package
v0.0.0-...-e3e1183 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

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

Protocol type definition

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

header direction definition

View Source
const (
	MosnHeaderDirection       = "x-mosn-direction" // for protocol convert
	MosnHeaderHostKey         = "x-mosn-host"
	MosnHeaderPathKey         = "x-mosn-path"
	MosnHeaderQueryStringKey  = "x-mosn-querystring"
	MosnHeaderMethod          = "x-mosn-method"
	MosnOriginalHeaderPathKey = "x-mosn-original-path"
)

Host key for routing in MOSN Header

View Source
const (
	IstioHeaderHostKey = "authority"
)

Hseader with special meaning in istio todo maybe use ":authority"

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 types.Protocol, srcData types.IoBuffer) (types.IoBuffer, error)

ConvertData convert data from source protocol format to destination protocol format

func ConvertHeader

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

ConvertHeader convert header from source protocol format to destination protocol format

func ConvertTrailer

func ConvertTrailer(ctx context.Context, src, dst types.Protocol, srcTrailer types.HeaderMap) (types.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(p types.Protocol, headers types.HeaderMap) (int, error)

func RegisterCommonConv

func RegisterCommonConv(protocol types.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 types.Protocol, f ProtocolConv)

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

func RegisterMapping

func RegisterMapping(p types.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() types.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(headers types.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) types.IoBuffer

GetReqData returns IoBuffer for request data

func (*ProtocolBuffers) GetReqHeader

func (p *ProtocolBuffers) GetReqHeader(size int) types.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) types.IoBuffer

GetRspData returns IoBuffer for response data

func (*ProtocolBuffers) GetRspHeader

func (p *ProtocolBuffers) GetRspHeader(size int) types.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 `types.HeaderMap`
	ConvHeader(ctx context.Context, headerMap types.HeaderMap) (types.HeaderMap, error)

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

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

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

Jump to

Keyboard shortcuts

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