swt

package
v1.0.18 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const LengthLength = 2
View Source
const LengthStartIndex = 2 // 数据部分长度起始字节位置
View Source
const LengthStopIndex = 4 // 数据部分长度结束字节位置
View Source
const TcpHeaderLength = VersionLength + LengthLength
View Source
const VersionLength = 2

Variables

View Source
var VersionContent = [2]byte{'v', '1'}

Functions

func DecodeSegment

func DecodeSegment(seg string) ([]byte, error)

DecodeSegment Decode JWT specific base64url encoding with padding stripped

func EncodeSegment

func EncodeSegment(seg []byte) string

EncodeSegment Encode JWT specific base64url encoding with padding stripped

func GenerateRandomKey

func GenerateRandomKey(length int) []byte

GenerateRandomKey generates a random bytes of the specified length

func GenerateRandomString

func GenerateRandomString(length int) string

GenerateRandomString generates a random string of the specified length

func New

func New[T IPayload](pl T, opts ...Opt) (string, error)

func Parse

func Parse[T IPayload](str string, pl T, opts ...Opt) error

Types

type BasicPayload

type BasicPayload struct {
	UserId int64
	Status uint8
	Name   string
}

func (*BasicPayload) Decode

func (p *BasicPayload) Decode(b []byte) error

func (*BasicPayload) Encode

func (p *BasicPayload) Encode() ([]byte, error)

func (*BasicPayload) Ver

func (p *BasicPayload) Ver() uint8

Ver return the unique id of payload.Must be unique!!!

type IPayload

type IPayload interface {
	Ver() uint8
	Encode() ([]byte, error)
	Decode([]byte) error
}

type Opt

type Opt func(s *swt)

func SecretKey

func SecretKey(key string) Opt

type StickPackage

type StickPackage struct {
	Version [2]byte // 协议版本
	Length  int16   // 数据部分长度
	Msg     []byte  // 数据
}

func (*StickPackage) GetPackageLength

func (p *StickPackage) GetPackageLength() int16

func (*StickPackage) Pack

func (p *StickPackage) Pack(writer io.Writer) error

func (*StickPackage) String

func (p *StickPackage) String() string

func (*StickPackage) Unpack

func (p *StickPackage) Unpack(reader io.Reader) error

Jump to

Keyboard shortcuts

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