utils

package
v0.0.0-...-6d0c0f3 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UShort HeaderType = 2
	UInt              = 4
	ULong             = 8
)

Variables

This section is empty.

Functions

func Ceil

func Ceil[T constraints.Integer](a, b T) T

Ceil 计算a/b取上整

func CeilUint64

func CeilUint64(a, b uint64) uint64

CeilUint64 计算a/b取上整

func EncryptBytes

func EncryptBytes(data []byte) string

func GenTLSConfig

func GenTLSConfig() *tls.Config

func GetObject

func GetObject(str []byte, v any) error

GetObject 数据转成对象

func GetSockoptInt

func GetSockoptInt(fd uintptr, level, opt int) (int, error)

func InitLog

func InitLog(level slog.Level, w io.Writer)

func InitProcess

func InitProcess()

func IsBefore

func IsBefore[T constraints.Integer](a, b, max T) bool

IsBefore 判断a是否比b小,支持数据溢出后的计算

func IsBefore8

func IsBefore8(a, b uint8) bool

IsBefore8 判断a是否比b小,支持数据溢出后的计算,如 255 比较 256

func IsBefore16

func IsBefore16(a, b uint16) bool

IsBefore16 判断a是否比b小,支持数据溢出后的计算,如 65535 比较 65536

func IsBefore32

func IsBefore32(a, b uint32) bool

IsBefore32 判断a是否比b小,支持数据溢出后的计算

func IsBefore64

func IsBefore64(a, b uint64) bool

IsBefore64 判断a是否比b小,支持数据溢出后的计算

func ReadStream

func ReadStream(stream *quic.Stream, length uint64) ([]byte, error)

ReadStream 从数据流中读取数据包,在接收完流的指定长度前不会返回

func ReadStreamByHeaderType

func ReadStreamByHeaderType(stream *quic.Stream, headerType HeaderType) ([]byte, error)

ReadStreamByHeaderType 从数据流中读取数据包,数据包的长度又类型提供简单的支持,且未接收完流前不会返回

func ReadStreamByHeaderUShort

func ReadStreamByHeaderUShort(stream *quic.Stream) ([]byte, error)

ReadStreamByHeaderUShort 从数据流中读取数据包,数据包长度类型为uint16,且未接收完流前不会返回

func ReadStreamFull

func ReadStreamFull(stream *quic.Stream, length uint64) ([]byte, error)

ReadStreamFull 从数据流中读取数据包,在接收完流的指定长度前不会返回

func ReadStreamWithTimeout

func ReadStreamWithTimeout(stream *quic.Stream, length uint64, timeout time.Duration) ([]byte, error)

ReadStreamWithTimeout 从数据流中读取数据包,在接收完流的指定长度前不会返回

func SetSocketReuse

func SetSocketReuse(fd uintptr)

func SetSockoptInt

func SetSockoptInt(fd uintptr, level, opt int, value int) (err error)

func SetSockoptMin

func SetSockoptMin(fd uintptr, level, opt int, value int) (err error)

func ToJsonByte

func ToJsonByte(v any) ([]byte, error)

ToJsonByte 对象转成json数据

func ToJsonString

func ToJsonString(v any) (string, error)

ToJsonString 对象转成json字符串

func WriteStream

func WriteStream(stream *quic.Stream, header, payload []byte) error

WriteStream 将数据包写入数据流,数据包包含数据头和载体,数据头允许为空

func WriteStreamByHeaderType

func WriteStreamByHeaderType(stream *quic.Stream, data []byte, headerType HeaderType) error

WriteStreamByHeaderType 将数据写入数据流,同时携带数据包长度作为报头,数据包长度类型根据输入headerType进行指定

func WriteStreamByHeaderUShort

func WriteStreamByHeaderUShort(stream *quic.Stream, data []byte) error

WriteStreamByHeaderUShort 将数据写入数据流,同时携带数据包长度作为报头,数据包长度类型为uint16

Types

type HeaderType

type HeaderType int

HeaderType 数据包头的类型

type JsonArray

type JsonArray []interface{}

JsonArray 定义JsonArray类型

func GetJsonArray

func GetJsonArray(str []byte) (JsonArray, error)

GetJsonArray 转成json数组

type JsonObject

type JsonObject map[string]interface{}

JsonObject 定义JsonObject类型

func GetJsonObject

func GetJsonObject(str []byte) (JsonObject, error)

GetJsonObject 转成json对象

type StreamResult

type StreamResult struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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