func (m meshHeader) encode(ctx context.Context, message remote.Message, payloadBuf, out remote.ByteBuffer) error {
	return nil
}
lint:ignore U1000 until encode is used
package codec
import (
	"context"
	"encoding/binary"
	"fmt"
	"io"
	"github.com/cloudwego/kitex/pkg/klog"
	"github.com/cloudwego/kitex/pkg/remote"
	"github.com/cloudwego/kitex/pkg/remote/codec/perrors"
	"github.com/cloudwego/kitex/pkg/serviceinfo"
)
const (
	TTHeaderMagic     uint32 = 0x10000000
	MeshHeaderMagic   uint32 = 0xFFAF0000
	MeshHeaderLenMask uint32 = 0x0000FFFF
	FlagsMask     uint32 = 0x0000FFFF
	MethodMask    uint32 = 0x41000000  
	MaxFrameSize  uint32 = 0x3FFFFFFF
	MaxHeaderSize uint32 = 65536
)
type HeaderFlags uint16
const (
	HeaderFlagsKey              string      = "HeaderFlags"
	HeaderFlagSupportOutOfOrder HeaderFlags = 0x01
	HeaderFlagDuplexReverse     HeaderFlags = 0x08
	HeaderFlagSASL              HeaderFlags = 0x10
)
const (
	TTHeaderMetaSize = 14
)
type ProtocolID uint8
const (
	ProtocolIDThriftBinary  ProtocolID = 0x00
	ProtocolIDThriftCompact ProtocolID = 0x02
	ProtocolIDProtobufKitex ProtocolID = 0x03
	ProtocolIDDefault                  = ProtocolIDThriftBinary
)
type InfoIDType uint8  
const (
	InfoIDPadding     InfoIDType = 0
	InfoIDKeyValue    InfoIDType = 0x01
	InfoIDIntKeyValue InfoIDType = 0x10
	InfoIDACLToken    InfoIDType = 0x11
)
type ttHeader struct{}
func (t ttHeader) encode(ctx context.Context, message remote.Message, out remote.ByteBuffer) (totalLenField []byte, err error) {
	var headerMeta []byte
	headerMeta, err = out.Malloc(TTHeaderMetaSize)
	if err != nil {
		return nil, perrors.NewProtocolErrorWithMsg(fmt.Sprintf("ttHeader malloc header meta failed, %s", err.Error()))
	}
	totalLenField = headerMeta[0:4]
	headerInfoSizeField := headerMeta[12:14]
	binary.BigEndian.PutUint32(headerMeta[4:8], TTHeaderMagic+uint32(getFlags(message)))
	binary.BigEndian.PutUint32(headerMeta[8:12], uint32(message.RPCInfo().Invocation().SeqID()))
	var transformIDs []uint8  
	if err = WriteByte(byte(getProtocolID(message.ProtocolInfo())), out); err != nil {
		return nil, perrors.NewProtocolErrorWithMsg(fmt.Sprintf("ttHeader write protocol id failed, %s", err.Error()))
	}
	if err = WriteByte(byte(len(transformIDs)), out); err != nil {
		return nil, perrors.NewProtocolErrorWithMsg(fmt.Sprintf("ttHeader write transformIDs length failed, %s", err.Error()))
	}
	for tid := range transformIDs {
		if err = WriteByte(byte(tid), out); err != nil {
			return nil, perrors.NewProtocolErrorWithMsg(fmt.Sprintf("ttHeader write transformIDs failed, %s", err.Error()))
		}
	}
	headerInfoSize := 1 + 1 + len(transformIDs)
	headerInfoSize, err = writeKVInfo(headerInfoSize, message, out)
	if err != nil {
		return nil, perrors.NewProtocolErrorWithMsg(fmt.Sprintf("ttHeader write kv info failed, %s", err.Error()))
	}
	binary.BigEndian.PutUint16(headerInfoSizeField, uint16(headerInfoSize/4))
	return totalLenField, err
}
func (t ttHeader) decode(ctx context.Context, message remote.Message, in remote.ByteBuffer) error {
	headerMeta, err := in.Next(TTHeaderMetaSize)
	if err != nil {
		return perrors.NewProtocolError(err)
	}
	if !IsTTHeader(headerMeta) {
		return perrors.NewProtocolErrorWithMsg("not TTHeader protocol")
	}
	totalLen := Bytes2Uint32NoCheck(headerMeta[:Size32])
	flags := Bytes2Uint16NoCheck(headerMeta[Size16*3:])
	setFlags(flags, message)
	seqID := Bytes2Uint32NoCheck(headerMeta[Size32*2 : Size32*3])
	if err = SetOrCheckSeqID(int32(seqID), message); err != nil {
		klog.Warnf("the seqID in TTHeader check failed, err=%s", err.Error())
	}
	headerInfoSize := Bytes2Uint16NoCheck(headerMeta[Size32*3:TTHeaderMetaSize]) * 4
	if uint32(headerInfoSize) > MaxHeaderSize || headerInfoSize < 2 {
		return perrors.NewProtocolErrorWithMsg(fmt.Sprintf("invalid header length[%d]", headerInfoSize))
	}
	var headerInfo []byte
	if headerInfo, err = in.Next(int(headerInfoSize)); err != nil {
		return perrors.NewProtocolError(err)
	}
	if err = checkProtocalID(headerInfo[0], message); err != nil {
		return err
	}
	hdIdx := 2
	transformIDNum := int(headerInfo[1])
	if int(headerInfoSize)-hdIdx < transformIDNum {
		return perrors.NewProtocolErrorWithType(perrors.InvalidData, fmt.Sprintf("need read %d transformIDs, but not enough", transformIDNum))
	}
	transformIDs := make([]uint8, transformIDNum)
	for i := 0; i < transformIDNum; i++ {
		transformIDs[i] = headerInfo[hdIdx]
		hdIdx++
	}
	if err := readKVInfo(hdIdx, headerInfo, message); err != nil {
		return perrors.NewProtocolErrorWithMsg(fmt.Sprintf("ttTHeader read kv info failed, %s", err.Error()))
	}
	message.SetPayloadLen(int(totalLen - uint32(headerInfoSize) + Size32 - TTHeaderMetaSize))
	return err
}
func writeKVInfo(writtenSize int, message remote.Message, out remote.ByteBuffer) (writeSize int, err error) {
	writeSize = writtenSize
	tm := message.TransInfo()
	strKVSize := len(tm.TransStrInfo())
	if strKVSize > 0 {
		if err = WriteByte(byte(InfoIDKeyValue), out); err != nil {
			return writeSize, err
		}
		if err = WriteUint16(uint16(strKVSize), out); err != nil {
			return writeSize, err
		}
		writeSize += 3
		for key, val := range tm.TransStrInfo() {
			keyWLen, err := WriteString2BLen(key, out)
			if err != nil {
				return writeSize, err
			}
			valWLen, err := WriteString2BLen(val, out)
			if err != nil {
				return writeSize, err
			}
			writeSize = writeSize + keyWLen + valWLen
		}
	}
	intKVSize := len(tm.TransIntInfo())
	if intKVSize > 0 {
		if err = WriteByte(byte(InfoIDIntKeyValue), out); err != nil {
			return writeSize, err
		}
		if err = WriteUint16(uint16(intKVSize), out); err != nil {
			return writeSize, err
		}
		writeSize += 3
		for key, val := range tm.TransIntInfo() {
			if err = WriteUint16(key, out); err != nil {
				return writeSize, err
			}
			valWLen, err := WriteString2BLen(val, out)
			if err != nil {
				return writeSize, err
			}
			writeSize = writeSize + 2 + valWLen
		}
	}
	padding := (4 - writeSize%4) % 4
	paddingBuf, err := out.Malloc(padding)
	if err != nil {
		return writeSize, err
	}
	for i := 0; i < len(paddingBuf); i++ {
		paddingBuf[i] = byte(0)
	}
	writeSize += padding
	return
}
func readKVInfo(idx int, buf []byte, message remote.Message) error {
	intInfo := message.TransInfo().TransIntInfo()
	strInfo := message.TransInfo().TransStrInfo()
	for {
		infoID, err := Bytes2Uint8(buf, idx)
		idx++
		if err != nil {
			if err == io.EOF {
				break
			} else {
				return err
			}
		}
		switch InfoIDType(infoID) {
		case InfoIDPadding:
			continue
		case InfoIDKeyValue:
			_, err := readStrKVInfo(&idx, buf, strInfo)
			if err != nil {
				return err
			}
		case InfoIDIntKeyValue:
			_, err := readIntKVInfo(&idx, buf, intInfo)
			if err != nil {
				return err
			}
		case InfoIDACLToken:
			err = skipACLToken(&idx, buf)
			if err != nil {
				return err
			}
		default:
			return fmt.Errorf("invalid infoIDType[%#x]", infoID)
		}
	}
	return nil
}
func readIntKVInfo(idx *int, buf []byte, info map[uint16]string) (has bool, err error) {
	kvSize, err := Bytes2Uint16(buf, *idx)
	*idx += 2
	if err != nil {
		return false, fmt.Errorf("error reading int kv info size: %s", err.Error())
	}
	if kvSize <= 0 {
		return false, nil
	}
	for i := uint16(0); i < kvSize; i++ {
		key, err := Bytes2Uint16(buf, *idx)
		*idx += 2
		if err != nil {
			return false, fmt.Errorf("error reading int kv info: %s", err.Error())
		}
		val, n, err := ReadString2BLen(buf, *idx)
		*idx += n
		if err != nil {
			return false, fmt.Errorf("error reading int kv info: %s", err.Error())
		}
		info[key] = val
	}
	return true, nil
}
func readStrKVInfo(idx *int, buf []byte, info map[string]string) (has bool, err error) {
	kvSize, err := Bytes2Uint16(buf, *idx)
	*idx += 2
	if err != nil {
		return false, fmt.Errorf("error reading str kv info size: %s", err.Error())
	}
	if kvSize <= 0 {
		return false, nil
	}
	for i := uint16(0); i < kvSize; i++ {
		key, n, err := ReadString2BLen(buf, *idx)
		*idx += n
		if err != nil {
			return false, fmt.Errorf("error reading str kv info: %s", err.Error())
		}
		val, n, err := ReadString2BLen(buf, *idx)
		*idx += n
		if err != nil {
			return false, fmt.Errorf("error reading str kv info: %s", err.Error())
		}
		info[key] = val
	}
	return true, nil
}
func skipACLToken(idx *int, buf []byte) error {
	_, n, err := ReadString2BLen(buf, *idx)
	*idx += n
	if err != nil {
		return fmt.Errorf("error reading acl token: %s", err.Error())
	}
	return nil
}
func getFlags(message remote.Message) HeaderFlags {
	var headerFlags HeaderFlags
	if message.Tags() != nil && message.Tags()[HeaderFlagsKey] != nil {
		headerFlags = message.Tags()[HeaderFlagsKey].(HeaderFlags)
	}
	return headerFlags
}
func setFlags(flags uint16, message remote.Message) {
	if message.MessageType() == remote.Call {
		message.Tags()[HeaderFlagsKey] = flags
	}
}
func getProtocolID(pi remote.ProtocolInfo) ProtocolID {
	switch pi.CodecType {
	case serviceinfo.Protobuf:
		return ProtocolIDProtobufKitex
	}
	return ProtocolIDDefault
}
func checkProtocalID(protoID uint8, message remote.Message) error {
	switch protoID {
	case uint8(ProtocolIDProtobufKitex):
	case uint8(ProtocolIDThriftBinary):
	default:
		return fmt.Errorf("unsupport ProtocolID[%d]", protoID)
	}
	return nil
}
type meshHeader struct{}