ttheader

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: Apache-2.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// Meta Size
	TTHeaderMetaSize = 14

	// Header Magics
	// 0 and 16th bits must be 0 to differentiate from framed & unframed
	TTHeaderMagic     uint32 = 0x10000000
	MeshHeaderMagic   uint32 = 0xFFAF0000
	MeshHeaderLenMask uint32 = 0x0000FFFF

	// HeaderMask        uint32 = 0xFFFF0000
	FlagsMask     uint32 = 0x0000FFFF
	MethodMask    uint32 = 0x41000000 // method first byte [A-Za-z_]
	MaxFrameSize  uint32 = 0x3FFFFFFF
	MaxHeaderSize uint32 = 65536
)

Header keys

View Source
const (
	FrameTypeMeta    = "1"
	FrameTypeHeader  = "2"
	FrameTypeData    = "3"
	FrameTypeTrailer = "4"
	FrameTypeInvalid = ""
)
View Source
const (
	MeshVersion uint16 = iota
	TransportType
	LogID
	FromService
	FromCluster
	FromIDC
	ToService
	ToCluster
	ToIDC
	ToMethod
	Env
	DestAddress
	RPCTimeout
	ReadTimeout
	RingHashKey
	DDPTag
	WithMeshHeader
	ConnectTimeout
	SpanContext
	ShortConnection
	FromMethod
	StressTag
	MsgType
	HTTPContentType
	RawRingHashKey
	LBType
	ClusterShardID
	FrameType // ttheader streaming frame type
)

uint16 keys in ttheader.

View Source
const (
	HeaderIDLServiceName      = "isn"
	HeaderTransRemoteAddr     = "rip"
	HeaderTransToCluster      = "tc"
	HeaderTransToIDC          = "ti"
	HeaderTransPerfTConnStart = "pcs"
	HeaderTransPerfTConnEnd   = "pce"
	HeaderTransPerfTSendStart = "pss"
	HeaderTransPerfTRecvStart = "prs"
	HeaderTransPerfTRecvEnd   = "pre"
	// the connection peer will shutdown later,so it send back the header to tell client to close the connection.
	HeaderConnectionReadyToReset = "crrst"
	HeaderProcessAtTime          = "K_ProcessAtTime"
)

string keys of ttheader transport

View Source
const (
	Size32 = 4
	Size16 = 2
)

The byte count of 32 and 16 integer values.

View Source
const (
	// GDPRToken is used to set up gdpr token into InfoIDACLToken
	GDPRToken = metainfo.PrefixTransient + "gdpr-token"
)

key of acl token You can set up acl token through metainfo. eg:

ctx = metainfo.WithValue(ctx, "gdpr-token", "your token")
View Source
const (
	// MagicMask is bit mask for checking version.
	MagicMask = 0xffff0000
)

Variables

This section is empty.

Functions

func Bytes2Uint16

func Bytes2Uint16(bytes []byte, off int) (uint16, error)

Bytes2Uint16 ...

func Bytes2Uint16NoCheck

func Bytes2Uint16NoCheck(bytes []byte) uint16

Bytes2Uint16NoCheck ...

func Bytes2Uint32NoCheck

func Bytes2Uint32NoCheck(bytes []byte) uint32

Bytes2Uint32NoCheck ...

func Bytes2Uint8

func Bytes2Uint8(bytes []byte, off int) (uint8, error)

Bytes2Uint8 ...

func Encode

func Encode(ctx context.Context, param EncodeParam, out bufiox.Writer) (totalLenField []byte, err error)

Encode encode ttheader to bufiox.Writer. NOTICE: Must call

`binary.BigEndian.PutUint32(totalLenField, uint32(totalLen))`

after encoding both header and payload data to set total length of a request/response. And `totalLen` should be the length of header + payload - 4. You may refer to unit tests for examples.

func EncodeToBytes

func EncodeToBytes(ctx context.Context, param EncodeParam) (buf []byte, err error)

EncodeToBytes encode ttheader to bytes. NOTICE: Must call

`binary.BigEndian.PutUint32(buf, uint32(totalLen))`

after encoding both header and payload data to set total length of a request/response. And `totalLen` should be the length of header + payload - 4. You may refer to unit tests for examples.

func IsStreaming added in v0.1.3

func IsStreaming(bytes []byte) bool

func IsTTHeader

func IsTTHeader(flagBuf []byte) bool

func ReadString2BLen

func ReadString2BLen(bytes []byte, off int) (string, int, error)

ReadString2BLen ...

func WriteByte

func WriteByte(val byte, out bufiox.Writer) error

WriteByte ...

func WriteString

func WriteString(val string, out bufiox.Writer) (int, error)

WriteString ...

func WriteString2BLen

func WriteString2BLen(val string, out bufiox.Writer) (int, error)

WriteString2BLen ...

func WriteUint16

func WriteUint16(val uint16, out bufiox.Writer) error

WriteUint16 ...

func WriteUint32

func WriteUint32(val uint32, out bufiox.Writer) error

WriteUint32 ...

Types

type DecodeParam

type DecodeParam struct {
	// Flags is used to set up header flags, default is 0.
	Flags HeaderFlags

	// SeqID is used to set up sequence id of a request/response.
	// MUST be unique for each request/response.
	SeqID int32

	// ProtocolID is used to set up protocol id of a request/response.
	// Default is ProtocolIDThriftBinary.
	ProtocolID ProtocolID

	// IntInfo is used to set up int key-value info into InfoIDIntKeyValue.
	// You can refer to metakey.go for more details.
	IntInfo map[uint16]string

	// StrInfo is used to set up string key-value info into InfoIDKeyValue.
	// You can refer to metakey.go for more details.
	StrInfo map[string]string

	// HeaderLen is used to set up header length of a request/response.
	HeaderLen int

	// PayloadLen is used to set up payload length of a request/response.
	PayloadLen int
}

DecodeParam is used to return the ttheader info after decoding.

func Decode

func Decode(ctx context.Context, in bufiox.Reader) (param DecodeParam, err error)

Decode decodes ttheader param from bufiox.Reader.

func DecodeFromBytes

func DecodeFromBytes(ctx context.Context, bs []byte) (param DecodeParam, err error)

DecodeFromBytes decodes ttheader param from bytes.

type EncodeParam

type EncodeParam struct {
	// Flags is used to set up header flags, default is 0.
	Flags HeaderFlags

	// SeqID is used to set up sequence id of a request/response.
	// MUST be unique for each request/response.
	SeqID int32

	// ProtocolID is used to set up protocol id of a request/response.
	// Default is ProtocolIDThriftBinary.
	ProtocolID ProtocolID

	// IntInfo is used to set up int key-value info into InfoIDIntKeyValue.
	// You can refer to metakey.go for more details.
	IntInfo map[uint16]string

	// StrInfo is used to set up string key-value info into InfoIDKeyValue.
	// You can refer to metakey.go for more details.
	StrInfo map[string]string
}

EncodeParam is used to set up params to encode ttheader.

type HeaderFlags

type HeaderFlags uint16
const (
	HeaderFlagsStreaming        HeaderFlags = 0b0000_0000_0000_0010
	HeaderFlagSupportOutOfOrder HeaderFlags = 0x01
	HeaderFlagDuplexReverse     HeaderFlags = 0x08
	HeaderFlagSASL              HeaderFlags = 0x10
)

type InfoIDType

type InfoIDType uint8 // uint8
const (
	InfoIDPadding     InfoIDType = 0
	InfoIDKeyValue    InfoIDType = 0x01
	InfoIDIntKeyValue InfoIDType = 0x10
	InfoIDACLToken    InfoIDType = 0x11
)

type ProtocolID

type ProtocolID uint8

ProtocolID is the wrapped protocol id used in THeader.

const (
	ProtocolIDThriftBinary    ProtocolID = 0x00
	ProtocolIDThriftCompact   ProtocolID = 0x02 // Kitex not support
	ProtocolIDThriftCompactV2 ProtocolID = 0x03 // Kitex not support
	ProtocolIDKitexProtobuf   ProtocolID = 0x04
	ProtocolIDThriftStruct    ProtocolID = 0x10 // TTHeader Streaming: only thrift struct encoded, no magic
	ProtocolIDProtobufStruct  ProtocolID = 0x11 // TTHeader Streaming: only protobuf struct encoded, no magic
	ProtocolIDDefault                    = ProtocolIDThriftBinary
)

Supported ProtocolID values.

Jump to

Keyboard shortcuts

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