util

package
v4.15.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: MIT Imports: 28 Imported by: 35

Documentation

Index

Constants

View Source
const (
	AMF0_NUMBER = iota // 浮点数
	AMF0_BOOLEAN
	AMF0_STRING
	AMF0_OBJECT
	AMF0_MOVIECLIP
	AMF0_NULL
	AMF0_UNDEFINED
	AMF0_REFERENCE
	AMF0_ECMA_ARRAY
	AMF0_END_OBJECT
	AMF0_STRICT_ARRAY
	AMF0_DATE
	AMF0_LONG_STRING
	AMF0_UNSUPPORTED
	AMF0_RECORDSET
	AMF0_XML_DOCUMENT
	AMF0_TYPED_OBJECT
	AMF0_AVMPLUS_OBJECT
)
View Source
const (
	AMF3_UNDEFINED = iota
	AMF3_NULL
	AMF3_FALSE
	AMF3_TRUE
	AMF3_INTEGER
	AMF3_DOUBLE
	AMF3_STRING
	AMF3_XML_DOC
	AMF3_DATE
	AMF3_ARRAY
	AMF3_OBJECT
	AMF3_XML
	AMF3_BYTE_ARRAY
	AMF3_VECTOR_INT
	AMF3_VECTOR_UINT
	AMF3_VECTOR_DOUBLE
	AMF3_VECTOR_OBJECT
	AMF3_DICTIONARY
)
View Source
const (
	APIErrorNone   = 0
	APIErrorDecode = iota + 4000
	APIErrorQueryParse
	APIErrorNoBody
)
View Source
const (
	APIErrorNotFound = iota + 4040
	APIErrorNoStream
	APIErrorNoConfig
	APIErrorNoPusher
	APIErrorNoSubscriber
	APIErrorNoSEI
)
View Source
const (
	APIErrorInternal = iota + 5000
	APIErrorJSONEncode
	APIErrorPublish
	APIErrorSave
	APIErrorOpen
)

Variables

View Source
var (
	END_OBJ   = []byte{0, 0, AMF0_END_OBJECT}
	ObjectEnd = &struct{}{}
	Undefined = &struct{}{}
)
View Source
var BigEndian bigEndian

BigEndian is the big-endian implementation of ByteOrder.

View Source
var Crc32_Table = []uint32{}/* 256 elements not displayed */
View Source
var EmptyLocker emptyLocker
View Source
var (
	FieldNoExist error = errors.New("field no exist")
)
View Source
var LittleEndian littleEndian
View Source
var Null = struct{}{}
View Source
var PoolSize = 16
View Source
var RTPReorderBufferLen uint16 = 50

Functions

func BasicAuth

func BasicAuth(u, p string, next http.Handler) http.Handler

func BigLittleSwap

func BigLittleSwap(v uint) uint

func Bit1

func Bit1(b byte, index int) bool

Bit1 检查字节中的某一位是否为1 |0|1|2|3|4|5|6|7|

func ByteToUint32

func ByteToUint32(data []byte, bigEndian bool) (ret uint32, err error)

千万注意大小端,RTMP是大端

func ByteToUint32N

func ByteToUint32N(data []byte) (ret uint32, err error)

// 千万注意大小端,RTMP是大端

func ByteToUint64N

func ByteToUint64N(data []byte) (ret uint64, err error)

// 千万注意大小端,RTMP是大端

func CORS

func CORS(next http.Handler) http.Handler

CORS 加入跨域策略头包含CORP

func Clone

func Clone[T any](x T) *T

func ConcatBuffers

func ConcatBuffers[T ~[]byte](input []T) (out []byte)

ConcatBuffers 合并碎片内存为一个完整内存

func Conditoinal added in v4.13.8

func Conditoinal[T any](cond bool, t, f T) T

func Conf2Listener added in v4.12.7

func Conf2Listener(conf string) (protocol string, ports []uint16)

func ConvertNum

func ConvertNum[F Integer, T Integer](from F, to T) T

func CreateShutdownScript

func CreateShutdownScript() error

func CurrentDir

func CurrentDir(path ...string) string

func Exist

func Exist(filename string) bool

检查文件或目录是否存在 如果由 filename 指定的文件或目录存在则返回 true,否则返回 false

func FetchValue added in v4.13.8

func FetchValue[T any](t T) func() T

func GetBE

func GetBE[T Integer](b []byte, num *T) T

func GetFillBytes

func GetFillBytes(data byte, n int) []byte

func GetPCR

func GetPCR(v uint64) uint64

func GetPtsDts

func GetPtsDts(v uint64) uint64

func GetUev

func GetUev(buff []byte, start int) (value int, pos int)

哥伦布解码

func IsLANAddr added in v4.11.15

func IsLANAddr(ip string) (bool, string)

IsLANAddr 检测 IP 地址字符串是否是内网地址

func IsLANIp added in v4.11.15

func IsLANIp(ip net.IP) (bool, string)

IsLANIp 检测 IP 地址是否是内网地址 通过直接对比ip段范围效率更高

func IsSubdir added in v4.13.0

func IsSubdir(baseDir, joinedDir string) bool

判断目录是否是基础目录的子目录

func LastElement

func LastElement[T any](s []T) T

func ListenUDP

func ListenUDP(address string, networkBuffer int) (*net.UDPConn, error)

func MapList added in v4.5.1

func MapList[K comparable, V any, R any](m *Map[K, V], f func(K, V) R) (r []R)

func MarshalAMFs added in v4.11.0

func MarshalAMFs(v ...any) []byte

func PutBE

func PutBE[T Integer](b []byte, num T) []byte

func PutPCR

func PutPCR(pcr uint64) uint64

func PutPtsDts

func PutPtsDts(v uint64) uint64

func ReadAMF added in v4.11.0

func ReadAMF[T string | float64 | bool | map[string]any](amf *AMF) (result T)

func ReadBE

func ReadBE[T Integer](b []byte) (num T)

func ReadByteToUint16

func ReadByteToUint16(r io.Reader, bigEndian bool) (data uint16, err error)

func ReadByteToUint24

func ReadByteToUint24(r io.Reader, bigEndian bool) (data uint32, err error)

func ReadByteToUint32

func ReadByteToUint32(r io.Reader, bigEndian bool) (data uint32, err error)

func ReadByteToUint40

func ReadByteToUint40(r io.Reader, bigEndian bool) (data uint64, err error)

func ReadByteToUint48

func ReadByteToUint48(r io.Reader, bigEndian bool) (data uint64, err error)

func ReadByteToUint64

func ReadByteToUint64(r io.Reader, bigEndian bool) (data uint64, err error)

func ReadByteToUint8

func ReadByteToUint8(r io.Reader) (data uint8, err error)

func Retry

func Retry(attempts int, sleep time.Duration, f func() error) error

func RetryStopErr

func RetryStopErr(err error) retryStop

func ReturnError added in v4.13.9

func ReturnError(code int, msg string, rw http.ResponseWriter, r *http.Request)

func ReturnFetchList added in v4.14.0

func ReturnFetchList[T any](fetch func() []T, rw http.ResponseWriter, r *http.Request)

func ReturnFetchValue added in v4.13.9

func ReturnFetchValue[T any](fetch func() T, rw http.ResponseWriter, r *http.Request)

func ReturnOK added in v4.13.9

func ReturnOK(rw http.ResponseWriter, r *http.Request)

func ReturnValue added in v4.13.9

func ReturnValue(v any, rw http.ResponseWriter, r *http.Request)

func SizeOfBuffers

func SizeOfBuffers[T ~[]byte](buf []T) (size int)

SizeOfBuffers 计算Buffers的内容长度

func SplitBuffers

func SplitBuffers[T ~[]byte](buf []T, size int) (result [][]T)

SplitBuffers 按照一定大小分割 Buffers

func ToFloat64

func ToFloat64(num interface{}) float64

func Uint32ToByte

func Uint32ToByte(data uint32, bigEndian bool) (ret []byte, err error)

func WaitTerm

func WaitTerm(cancel context.CancelFunc)

func WriteUint16ToByte

func WriteUint16ToByte(w io.Writer, data uint16, bigEndian bool) error

func WriteUint24ToByte

func WriteUint24ToByte(w io.Writer, data uint32, bigEndian bool) error

func WriteUint32ToByte

func WriteUint32ToByte(w io.Writer, data uint32, bigEndian bool) error

func WriteUint40ToByte

func WriteUint40ToByte(w io.Writer, data uint64, bigEndian bool) error

func WriteUint48ToByte

func WriteUint48ToByte(w io.Writer, data uint64, bigEndian bool) error

func WriteUint64ToByte

func WriteUint64ToByte(w io.Writer, data uint64, bigEndian bool) error

func WriteUint8ToByte

func WriteUint8ToByte(w io.Writer, data uint8) error

Types

type AMF added in v4.11.0

type AMF struct {
	Buffer
}

func (*AMF) Marshal added in v4.11.0

func (amf *AMF) Marshal(v any) []byte

func (*AMF) Marshals added in v4.11.0

func (amf *AMF) Marshals(v ...any) []byte

func (*AMF) ReadBool added in v4.11.0

func (amf *AMF) ReadBool() (result bool)

func (*AMF) ReadNumber added in v4.11.0

func (amf *AMF) ReadNumber() (result float64)

func (*AMF) ReadObject added in v4.11.0

func (amf *AMF) ReadObject() (result map[string]any)

func (*AMF) ReadShortString added in v4.11.0

func (amf *AMF) ReadShortString() (result string)

func (*AMF) Unmarshal added in v4.11.0

func (amf *AMF) Unmarshal() (obj any, err error)

type APIError added in v4.13.9

type APIError struct {
	Code    int    `json:"code"`
	Message string `json:"msg"`
}

type APIResult added in v4.13.9

type APIResult struct {
	Code    int    `json:"code"`
	Data    any    `json:"data"`
	Message string `json:"msg"`
}

type BLL added in v4.11.0

type BLL struct {
	List[Buffer]
	ByteLength int
}

ByteLinkList

func (*BLL) Clear added in v4.11.0

func (list *BLL) Clear()

func (*BLL) GetByte added in v4.11.0

func (list *BLL) GetByte(index int) (b byte)

func (*BLL) GetUint24 added in v4.11.0

func (list *BLL) GetUint24(index int) uint32

func (*BLL) GetUintN added in v4.11.0

func (list *BLL) GetUintN(index int, n int) (result uint32)

func (*BLL) NewReader added in v4.11.0

func (list *BLL) NewReader() *BLLReader

func (*BLL) Push added in v4.11.0

func (list *BLL) Push(item *ListItem[Buffer])

func (*BLL) Recycle added in v4.11.0

func (list *BLL) Recycle()

全部回收掉

func (*BLL) Shift added in v4.11.0

func (list *BLL) Shift() (item *ListItem[Buffer])

func (*BLL) ToBuffers added in v4.11.0

func (list *BLL) ToBuffers() (result net.Buffers)

func (*BLL) ToBytes added in v4.11.0

func (list *BLL) ToBytes() (b []byte)

func (*BLL) WriteTo added in v4.11.0

func (list *BLL) WriteTo(w io.Writer) (int64, error)

type BLLReader added in v4.11.0

type BLLReader struct {
	*ListItem[Buffer]
	// contains filtered or unexported fields
}

func (*BLLReader) CanRead added in v4.11.0

func (r *BLLReader) CanRead() bool

func (*BLLReader) GetOffset added in v4.11.14

func (r *BLLReader) GetOffset() int

func (*BLLReader) LEB128Unmarshal added in v4.14.3

func (r *BLLReader) LEB128Unmarshal() (uint, int, error)

func (*BLLReader) ReadBE added in v4.11.0

func (r *BLLReader) ReadBE(n int) (be uint32, err error)

func (*BLLReader) ReadByte added in v4.11.0

func (r *BLLReader) ReadByte() (b byte, err error)

func (*BLLReader) ReadN added in v4.11.0

func (r *BLLReader) ReadN(n int) (result net.Buffers)

func (*BLLReader) Skip added in v4.11.0

func (r *BLLReader) Skip(n int) (err error)

func (*BLLReader) WriteNTo added in v4.12.8

func (r *BLLReader) WriteNTo(n int, result *net.Buffers) (actual int)

type BLLs added in v4.11.0

type BLLs struct {
	List[*BLL]
	ByteLength int
}

func (*BLLs) NewReader added in v4.11.0

func (list *BLLs) NewReader() *BLLsReader

func (*BLLs) Push added in v4.11.0

func (list *BLLs) Push(item *ListItem[Buffer])

func (*BLLs) PushValue added in v4.11.0

func (list *BLLs) PushValue(item *BLL)

func (*BLLs) Recycle added in v4.11.0

func (list *BLLs) Recycle()

func (*BLLs) ToBuffers added in v4.11.5

func (list *BLLs) ToBuffers() (result net.Buffers)

func (*BLLs) ToBytes added in v4.11.0

func (list *BLLs) ToBytes() (result []byte)

func (*BLLs) ToList added in v4.11.0

func (list *BLLs) ToList() (result [][][]byte)

type BLLsReader added in v4.11.0

type BLLsReader struct {
	*ListItem[*BLL]
	BLLReader
}

func (*BLLsReader) CanRead added in v4.11.0

func (r *BLLsReader) CanRead() bool

func (*BLLsReader) ReadByte added in v4.11.0

func (r *BLLsReader) ReadByte() (b byte, err error)

type Buffer

type Buffer []byte

Buffer 用于方便自动扩容的内存写入,已经读取

func (Buffer) Bytes added in v4.13.0

func (b Buffer) Bytes() []byte

func (Buffer) CanRead

func (b Buffer) CanRead() bool

func (Buffer) CanReadN added in v4.9.9

func (b Buffer) CanReadN(n int) bool

func (Buffer) Cap

func (b Buffer) Cap() int

func (Buffer) Clone added in v4.12.9

func (b Buffer) Clone() (result Buffer)

func (Buffer) Len

func (b Buffer) Len() int

func (*Buffer) Malloc

func (b *Buffer) Malloc(count int) Buffer

Malloc 扩大原来的buffer的长度,返回新增的buffer

func (*Buffer) MarshalAMFs added in v4.11.0

func (b *Buffer) MarshalAMFs(v ...any)

func (*Buffer) Read added in v4.11.5

func (b *Buffer) Read(buf []byte) (n int, err error)

func (*Buffer) ReadByte

func (b *Buffer) ReadByte() byte

func (*Buffer) ReadFloat64

func (b *Buffer) ReadFloat64() float64

func (*Buffer) ReadN

func (b *Buffer) ReadN(n int) Buffer

func (*Buffer) ReadUint16

func (b *Buffer) ReadUint16() uint16

func (*Buffer) ReadUint24

func (b *Buffer) ReadUint24() uint32

func (*Buffer) ReadUint32

func (b *Buffer) ReadUint32() uint32

func (*Buffer) ReadUint64

func (b *Buffer) ReadUint64() uint64

func (*Buffer) Relloc added in v4.11.18

func (b *Buffer) Relloc(count int)

Relloc 改变 buffer 到指定大小

func (*Buffer) Reset

func (b *Buffer) Reset()

func (Buffer) Reuse added in v4.13.0

func (Buffer) Reuse() bool

func (*Buffer) Split added in v4.11.0

func (b *Buffer) Split(n int) (result net.Buffers)

func (Buffer) SubBuf

func (b Buffer) SubBuf(start int, length int) Buffer

func (*Buffer) Write

func (b *Buffer) Write(a []byte) (n int, err error)

func (*Buffer) WriteByte

func (b *Buffer) WriteByte(v byte)

func (*Buffer) WriteFloat64

func (b *Buffer) WriteFloat64(v float64)

func (*Buffer) WriteString

func (b *Buffer) WriteString(a string)

func (*Buffer) WriteUint16

func (b *Buffer) WriteUint16(v uint16)

func (*Buffer) WriteUint24

func (b *Buffer) WriteUint24(v uint32)

func (*Buffer) WriteUint32

func (b *Buffer) WriteUint32(v uint32)

type Builder added in v4.12.10

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

构造器

func NewBuilder added in v4.12.10

func NewBuilder() *Builder

func (*Builder) AddBool added in v4.12.10

func (b *Builder) AddBool(name string) *Builder

func (*Builder) AddField added in v4.12.10

func (b *Builder) AddField(field string, typ reflect.Type) *Builder

添加字段

func (*Builder) AddFloat64 added in v4.12.10

func (b *Builder) AddFloat64(name string) *Builder

func (*Builder) AddInt64 added in v4.12.10

func (b *Builder) AddInt64(name string) *Builder

func (*Builder) AddString added in v4.12.10

func (b *Builder) AddString(name string) *Builder

func (*Builder) Build added in v4.12.10

func (b *Builder) Build() *Struct

根据预先添加的字段构建出结构体

type BytesPool added in v4.11.0

type BytesPool []List[Buffer]

func (BytesPool) Get added in v4.11.0

func (p BytesPool) Get(size int) (item *ListItem[Buffer])

func (BytesPool) GetShell added in v4.11.0

func (p BytesPool) GetShell(b []byte) (item *ListItem[Buffer])

获取来自真实内存的切片的——假内存块,即只回收外壳

type Crc32Reader

type Crc32Reader struct {
	R     io.Reader
	Crc32 uint32
}

func (*Crc32Reader) Read

func (cr *Crc32Reader) Read(b []byte) (n int, err error)

func (*Crc32Reader) ReadCrc32UIntAndCheck

func (cr *Crc32Reader) ReadCrc32UIntAndCheck() (err error)

type Crc32Writer

type Crc32Writer struct {
	W     io.Writer
	Crc32 uint32
}

func (*Crc32Writer) Write

func (wr *Crc32Writer) Write(b []byte) (n int, err error)

type DTSEstimator added in v4.15.0

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

DTSEstimator is a DTS estimator.

func NewDTSEstimator added in v4.15.0

func NewDTSEstimator() *DTSEstimator

NewDTSEstimator allocates a DTSEstimator.

func (*DTSEstimator) Clone added in v4.15.0

func (d *DTSEstimator) Clone() *DTSEstimator

func (*DTSEstimator) Feed added in v4.15.0

func (d *DTSEstimator) Feed(pts uint32) uint32

Feed provides PTS to the estimator, and returns the estimated DTS.

type EcmaArray added in v4.11.0

type EcmaArray map[string]any

type IBytes added in v4.13.0

type IBytes interface {
	Len() int
	Bytes() []byte
	Reuse() bool
}

IBytes 用于区分传入的内存是否是复用内存,例如从网络中读取的数据,如果是复用内存,需要尽早复制

type IDataFrame added in v4.15.0

type IDataFrame[T any] interface {
	Init()               // 初始化
	Reset()              // 重置数据,复用内存
	Ready()              // 标记为可读取
	ReaderEnter() int32  // 读取者数量+1
	ReaderLeave() int32  // 读取者数量-1
	StartWrite() bool    // 开始写入
	SetSequence(uint32)  // 设置序号
	GetSequence() uint32 // 获取序号
	ReaderCount() int32  // 读取者数量
	Discard() int32      // 如果写入时还有读取者没有离开则废弃该帧,剥离RingBuffer,防止并发读写
	IsDiscarded() bool   // 是否已废弃
	IsWriting() bool     // 是否正在写入
	Wait()               // 阻塞等待可读取
	Broadcast()          // 广播可读取
}

type IList added in v4.11.0

type IList[T any] interface {
	Push(*ListItem[T])
	Shift() *ListItem[T]
	Clear()
}

type IOVec

type IOVec struct {
	Data   [][]byte
	Length int
	// contains filtered or unexported fields
}

func (*IOVec) Append

func (iov *IOVec) Append(b []byte)

func (*IOVec) WriteTo

func (iov *IOVec) WriteTo(w io.Writer, n int) (written int, err error)

type IOVecWriter

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

func NewIOVecWriter

func NewIOVecWriter(w io.Writer) (iow *IOVecWriter)

func (*IOVecWriter) Flush

func (iow *IOVecWriter) Flush() error

func (*IOVecWriter) Write

func (iow *IOVecWriter) Write(data []byte) (written int, err error)

type Instance added in v4.12.10

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

结构体的值

func (*Instance) Addr added in v4.12.10

func (i *Instance) Addr() interface{}

func (Instance) Field added in v4.12.10

func (in Instance) Field(name string) (reflect.Value, error)

func (*Instance) Interface added in v4.12.10

func (i *Instance) Interface() interface{}

func (*Instance) SetBool added in v4.12.10

func (in *Instance) SetBool(name string, value bool)

func (*Instance) SetFloat64 added in v4.12.10

func (in *Instance) SetFloat64(name string, value float64)

func (*Instance) SetInt64 added in v4.12.10

func (in *Instance) SetInt64(name string, value int64)

func (*Instance) SetString added in v4.12.10

func (in *Instance) SetString(name, value string)

type Integer

type Integer interface {
	~int | ~int16 | ~int32 | ~int64 | ~uint | ~uint16 | ~uint32 | ~uint64
}

type LimitBuffer added in v4.13.0

type LimitBuffer struct {
	Buffer
}

LimitBuffer 限制buffer的长度,不会改变原来的buffer,防止内存泄漏

func (LimitBuffer) Clone added in v4.13.0

func (b LimitBuffer) Clone() (result LimitBuffer)

func (*LimitBuffer) Malloc added in v4.13.0

func (b *LimitBuffer) Malloc(count int) (result LimitBuffer)

func (*LimitBuffer) ReadN added in v4.13.0

func (b *LimitBuffer) ReadN(n int) (result LimitBuffer)

func (LimitBuffer) SubBuf added in v4.13.0

func (b LimitBuffer) SubBuf(start int, length int) (result LimitBuffer)

func (*LimitBuffer) Write added in v4.13.0

func (b *LimitBuffer) Write(a []byte) (n int, err error)

type List added in v4.11.0

type List[T any] struct {
	ListItem[T]
	Length int
}

func (*List[T]) Clear added in v4.11.0

func (p *List[T]) Clear()

func (*List[T]) PoolShift added in v4.11.0

func (p *List[T]) PoolShift() (head *ListItem[T])

func (*List[T]) Push added in v4.11.0

func (p *List[T]) Push(item *ListItem[T])

func (*List[T]) PushValue added in v4.11.0

func (p *List[T]) PushValue(value T)

func (*List[T]) Range added in v4.11.0

func (p *List[T]) Range(do func(value T) bool)

func (*List[T]) RangeItem added in v4.11.0

func (p *List[T]) RangeItem(do func(*ListItem[T]) bool)

func (*List[T]) Recycle added in v4.11.0

func (p *List[T]) Recycle()

func (*List[T]) Shift added in v4.11.0

func (p *List[T]) Shift() (head *ListItem[T])

func (*List[T]) ShiftValue added in v4.11.0

func (p *List[T]) ShiftValue() T

func (*List[T]) Transfer added in v4.11.0

func (p *List[T]) Transfer(target IList[T])

Transfer 把链表中的所有元素转移到另一个链表中

func (*List[T]) Unshift added in v4.11.0

func (p *List[T]) Unshift(item *ListItem[T])

func (*List[T]) UnshiftValue added in v4.11.0

func (p *List[T]) UnshiftValue(value T)

type ListItem added in v4.11.0

type ListItem[T any] struct {
	Value     T
	Next, Pre *ListItem[T] `json:"-" yaml:"-"`
	Pool      *List[T]     `json:"-" yaml:"-"` // 回收池
	// contains filtered or unexported fields
}

func NewListItem added in v4.14.1

func NewListItem[T any](value T) *ListItem[T]

func (*ListItem[T]) InsertAfter added in v4.11.0

func (item *ListItem[T]) InsertAfter(insert *ListItem[T])

func (*ListItem[T]) InsertAfterValue added in v4.11.0

func (item *ListItem[T]) InsertAfterValue(value T) (result *ListItem[T])

func (*ListItem[T]) InsertBefore added in v4.11.0

func (item *ListItem[T]) InsertBefore(insert *ListItem[T])

func (*ListItem[T]) InsertBeforeValue added in v4.11.0

func (item *ListItem[T]) InsertBeforeValue(value T) (result *ListItem[T])

func (*ListItem[T]) IsRoot added in v4.11.0

func (item *ListItem[T]) IsRoot() bool

func (*ListItem[T]) Range added in v4.11.0

func (item *ListItem[T]) Range(do func(value T) bool)

func (*ListItem[T]) RangeItem added in v4.11.0

func (item *ListItem[T]) RangeItem(do func(*ListItem[T]) bool)

func (*ListItem[T]) Recycle added in v4.11.0

func (item *ListItem[T]) Recycle()

type Map

type Map[K comparable, V any] struct {
	sync.Map
}

func (*Map[K, V]) Add

func (m *Map[K, V]) Add(k K, v V) bool

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(k K) (v V, ok bool)

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(k K) (result V)

func (*Map[K, V]) Has

func (m *Map[K, V]) Has(k K) (ok bool)

func (*Map[K, V]) Len

func (m *Map[K, V]) Len() (l int)

func (*Map[K, V]) Range

func (m *Map[K, V]) Range(f func(K, V))

func (*Map[K, V]) Set

func (m *Map[K, V]) Set(k K, v V)

func (*Map[K, V]) ToList

func (m *Map[K, V]) ToList() (r []V)

type Pool added in v4.11.0

type Pool[T any] List[T]

func (*Pool[T]) Get added in v4.11.0

func (p *Pool[T]) Get() (item *ListItem[T])

type Promise

type Promise[S any] struct {
	context.Context
	context.CancelCauseFunc
	context.CancelFunc
	Value S
}

func NewPromise

func NewPromise[S any](value S) *Promise[S]

func (*Promise[S]) Await added in v4.9.0

func (p *Promise[S]) Await() (err error)

func (*Promise[S]) Reject

func (r *Promise[S]) Reject(err error)

func (*Promise[S]) Resolve

func (r *Promise[S]) Resolve()

func (*Promise[S]) Then

func (p *Promise[S]) Then(resolved func(S), rejected func(error))

type RTPReorder added in v4.7.7

type RTPReorder[T comparable] struct {
	Total uint32 // 总共收到的包数量
	Drop  uint32 // 丢弃的包数量
	// contains filtered or unexported fields
}

RTPReorder RTP包乱序重排

func (*RTPReorder[T]) Pop added in v4.7.7

func (p *RTPReorder[T]) Pop() (result T)

Pop 从缓存中取出一个包,需要连续调用直到返回nil

func (*RTPReorder[T]) Push added in v4.7.7

func (p *RTPReorder[T]) Push(seq uint16, v T) (result T)

type Recyclable added in v4.11.10

type Recyclable interface {
	Recycle()
}

type ReuseBuffer added in v4.13.0

type ReuseBuffer struct {
	Buffer
}

ReuseBuffer 重用buffer,内容可能会被覆盖,要尽早复制

func (ReuseBuffer) Reuse added in v4.13.0

func (ReuseBuffer) Reuse() bool

type Ring

type Ring[T any] struct {
	Value T // for use by client; untouched by this library
	// contains filtered or unexported fields
}

A Ring is an element of a circular list, or ring. Rings do not have a beginning or end; a pointer to any ring element serves as reference to the entire ring. Empty rings are represented as nil Ring pointers. The zero value for a Ring is a one-element ring with a nil Value.

func NewRing

func NewRing[T any](n int) *Ring[T]

New creates a ring of n elements.

func (*Ring[T]) Do

func (r *Ring[T]) Do(f func(T))

Do calls function f on each element of the ring, in forward order. The behavior of Do is undefined if f changes *r.

func (*Ring[T]) Len

func (r *Ring[T]) Len() int

Len computes the number of elements in ring r. It executes in time proportional to the number of elements.

func (r *Ring[T]) Link(s *Ring[T]) *Ring[T]

Link connects ring r with ring s such that r.Next() becomes s and returns the original value for r.Next(). r must not be empty.

If r and s point to the same ring, linking them removes the elements between r and s from the ring. The removed elements form a subring and the result is a reference to that subring (if no elements were removed, the result is still the original value for r.Next(), and not nil).

If r and s point to different rings, linking them creates a single ring with the elements of s inserted after r. The result points to the element following the last element of s after insertion.

func (*Ring[T]) Move

func (r *Ring[T]) Move(n int) *Ring[T]

Move moves n % r.Len() elements backward (n < 0) or forward (n >= 0) in the ring and returns that ring element. r must not be empty.

func (*Ring[T]) Next

func (r *Ring[T]) Next() *Ring[T]

Next returns the next ring element. r must not be empty.

func (*Ring[T]) Prev

func (r *Ring[T]) Prev() *Ring[T]

Prev returns the previous ring element. r must not be empty.

func (r *Ring[T]) Unlink(n int) *Ring[T]

Unlink removes n % r.Len() elements from the ring r, starting at r.Next(). If n % r.Len() == 0, r remains unchanged. The result is the removed subring. r must not be empty.

type RingWriter added in v4.15.0

type RingWriter[T any, F IDataFrame[T]] struct {
	*Ring[F]    `json:"-" yaml:"-"`
	ReaderCount atomic.Int32 `json:"-" yaml:"-"`

	Size      int
	LastValue F
	// contains filtered or unexported fields
}

func (*RingWriter[T, F]) GetReaderCount added in v4.15.0

func (rb *RingWriter[T, F]) GetReaderCount() int32

func (*RingWriter[T, F]) Glow added in v4.15.0

func (rb *RingWriter[T, F]) Glow(size int) (newItem *Ring[F])

func (*RingWriter[T, F]) Init added in v4.15.0

func (rb *RingWriter[T, F]) Init(n int, constructor func() F) *RingWriter[T, F]

func (*RingWriter[T, F]) Recycle added in v4.15.0

func (rb *RingWriter[T, F]) Recycle(r *Ring[F])

func (*RingWriter[T, F]) Reduce added in v4.15.0

func (rb *RingWriter[T, F]) Reduce(size int)

func (*RingWriter[T, F]) Step added in v4.15.0

func (rb *RingWriter[T, F]) Step() (normal bool)

type SSE

type SSE struct {
	http.ResponseWriter
	context.Context
}

func NewSSE

func NewSSE(w http.ResponseWriter, ctx context.Context) *SSE

func (*SSE) Write

func (sse *SSE) Write(data []byte) (n int, err error)

func (*SSE) WriteEvent

func (sse *SSE) WriteEvent(event string, data []byte) (err error)

func (*SSE) WriteExec

func (sse *SSE) WriteExec(cmd *exec.Cmd) error

func (*SSE) WriteJSON

func (sse *SSE) WriteJSON(data any) error

func (*SSE) WriteYAML added in v4.12.0

func (sse *SSE) WriteYAML(data any) error

type SafeChan

type SafeChan[T any] struct {
	C chan T
	// contains filtered or unexported fields
}

SafeChan安全的channel,可以防止close后被写入的问题

func (*SafeChan[T]) Close

func (sc *SafeChan[T]) Close() bool

Close senders为0的时候可以安全关闭,否则不能关闭

func (*SafeChan[T]) Init

func (sc *SafeChan[T]) Init(n int)

func (*SafeChan[T]) IsClosed

func (sc *SafeChan[T]) IsClosed() bool

func (*SafeChan[T]) IsEmpty

func (sc *SafeChan[T]) IsEmpty() bool

func (*SafeChan[T]) IsFull

func (sc *SafeChan[T]) IsFull() bool

func (*SafeChan[T]) Send

func (sc *SafeChan[T]) Send(v T) bool

type Slice

type Slice[T comparable] []T

func (*Slice[T]) Add

func (s *Slice[T]) Add(v T)

func (*Slice[T]) Delete

func (s *Slice[T]) Delete(v T) bool

func (Slice[T]) Len

func (s Slice[T]) Len() int

func (*Slice[T]) Reset

func (s *Slice[T]) Reset()

func (*Slice[T]) ResetAppend

func (s *Slice[T]) ResetAppend(first T)

type Struct added in v4.12.10

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

实际生成的结构体,基类 结构体的类型

func (Struct) New added in v4.12.10

func (s Struct) New() *Instance

type SysIOVec

type SysIOVec struct {
	Base   uintptr
	Length uint64
}

type TimestampProcessor added in v4.14.7

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

定义一个全局结构来存储状态

func (*TimestampProcessor) ProcessTimestamp added in v4.14.7

func (p *TimestampProcessor) ProcessTimestamp(timestamp int) int

处理单个时间戳的函数

Directories

Path Synopsis
pio

Jump to

Keyboard shortcuts

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