codec

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: Apache-2.0 Imports: 24 Imported by: 7

Documentation

Index

Constants

View Source
const (
	Size32 = 4
	Size16 = 2
)

The byte count of 32 and 16 integer values.

View Source
const (
	// ThriftV1Magic is the magic code for thrift.VERSION_1
	ThriftV1Magic = 0x80010000
	// ProtobufV1Magic is the magic code for kitex protobuf
	ProtobufV1Magic = 0x90010000

	// MagicMask is bit mask for checking version.
	MagicMask = 0xffff0000
)
View Source
const (
	// 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 (
	HeaderFlagsKey              string      = "HeaderFlags"
	HeaderFlagSupportOutOfOrder HeaderFlags = 0x01
	HeaderFlagDuplexReverse     HeaderFlags = 0x08
	HeaderFlagSASL              HeaderFlags = 0x10
)
View Source
const (
	// FrontMask is used in protocol sniffing.
	FrontMask = 0x0000ffff
)
View Source
const (
	PayloadValidatorPrefix = "PV_"
)
View Source
const (
	TTHeaderMetaSize = 14
)

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 Bytes2Uint32

func Bytes2Uint32(bytes []byte) (uint32, error)

Bytes2Uint32 ...

func Bytes2Uint32NoCheck

func Bytes2Uint32NoCheck(bytes []byte) uint32

Bytes2Uint32NoCheck ...

func Bytes2Uint8

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

Bytes2Uint8 ...

func IsTTHeader

func IsTTHeader(flagBuf []byte) bool

*

  • +------------------------------------------------------------+
  • | 4Byte | 2Byte |
  • +------------------------------------------------------------+
  • | Length | HEADER MAGIC |
  • +------------------------------------------------------------+

func NewDataIfNeeded

func NewDataIfNeeded(method string, message remote.Message) error

NewDataIfNeeded is used to create the data if not exist.

func NewDefaultCodec

func NewDefaultCodec() remote.Codec

NewDefaultCodec creates the default protocol sniffing codec supporting thrift and protobuf.

func NewDefaultCodecWithConfig added in v0.11.0

func NewDefaultCodecWithConfig(cfg CodecConfig) remote.Codec

NewDefaultCodecWithConfig creates the default protocol sniffing codec supporting thrift and protobuf with the input config.

func NewDefaultCodecWithSizeLimit added in v0.2.0

func NewDefaultCodecWithSizeLimit(maxSize int) remote.Codec

NewDefaultCodecWithSizeLimit creates the default protocol sniffing codec supporting thrift and protobuf but with size limit. maxSize is in bytes

func PeekUint32

func PeekUint32(in remote.ByteBuffer) (uint32, error)

PeekUint32 ...

func ReadString

func ReadString(in remote.ByteBuffer) (string, int, error)

ReadString ...

func ReadString2BLen

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

ReadString2BLen ...

func ReadUint16

func ReadUint16(in remote.ByteBuffer) (uint16, error)

ReadUint16 ...

func ReadUint32

func ReadUint32(in remote.ByteBuffer) (uint32, error)

ReadUint32 ...

func SetOrCheckMethodName

func SetOrCheckMethodName(methodName string, message remote.Message) error

SetOrCheckMethodName is used to set method name to invocation.

func SetOrCheckSeqID

func SetOrCheckSeqID(seqID int32, message remote.Message) error

SetOrCheckSeqID is used to check the sequence ID.

func UpdateMsgType

func UpdateMsgType(msgType uint32, message remote.Message) error

UpdateMsgType updates msg type.

func WriteByte

func WriteByte(val byte, out remote.ByteBuffer) error

WriteByte ...

func WriteString

func WriteString(val string, out remote.ByteBuffer) (int, error)

WriteString ...

func WriteString2BLen

func WriteString2BLen(val string, out remote.ByteBuffer) (int, error)

WriteString2BLen ...

func WriteUint16

func WriteUint16(val uint16, out remote.ByteBuffer) error

WriteUint16 ...

func WriteUint32

func WriteUint32(val uint32, out remote.ByteBuffer) error

WriteUint32 ...

Types

type CodecConfig added in v0.11.0

type CodecConfig struct {
	// maxSize limits the max size of the payload
	MaxSize int

	// If crc32Check is true, the codec will validate the payload using crc32c.
	// Only effective when transport is TTHeader.
	// Payload is all the data after TTHeader.
	CRC32Check bool

	// PayloadValidator is used to validate payload with customized checksum logic.
	// It prepares a value based on payload in sender-side and validates the value in receiver-side.
	// It can only be used when ttheader is enabled.
	PayloadValidator PayloadValidator
}

CodecConfig is the config of defaultCodec

type HeaderFlags

type HeaderFlags uint16

type InfoIDType

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

type PayloadValidator added in v0.11.0

type PayloadValidator interface {
	// Key returns a key for your validator, which will be the key in ttheader
	Key(ctx context.Context) string

	// Generate generates the checksum of the payload.
	// The value will not be set to the request header if "need" is false.
	// DO NOT modify the input payload since it might be obtained by nocopy API from the underlying buffer.
	Generate(ctx context.Context, outboundPayload []byte) (need bool, checksum string, err error)

	// Validate validates the input payload with the attached checksum.
	// Return pass if validation succeed, or return error.
	// DO NOT modify the input payload since it might be obtained by nocopy API from the underlying buffer.
	Validate(ctx context.Context, expectedValue string, inboundPayload []byte) (pass bool, err error)
}

PayloadValidator is the interface for validating the payload of RPC requests, which allows customized Checksum function.

func NewCRC32PayloadValidator added in v0.11.0

func NewCRC32PayloadValidator() PayloadValidator

NewCRC32PayloadValidator returns a new crcPayloadValidator

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
	ProtocolIDDefault                    = ProtocolIDThriftBinary
)

Supported ProtocolID values.

Directories

Path Synopsis
encoding
Package encoding defines the interface for the compressor and codec, and functions to register and retrieve compressors and codecs.
Package encoding defines the interface for the compressor and codec, and functions to register and retrieve compressors and codecs.
encoding/gzip
Package gzip implements and registers the gzip compressor during the initialization.
Package gzip implements and registers the gzip compressor during the initialization.

Jump to

Keyboard shortcuts

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