DxCommonLib

package module
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: MIT Imports: 22 Imported by: 5

Documentation

Overview

从fasthttp中变更过来的GoRoutine池 Autor: 不得闲 QQ:75492895

仿Delphi的通用类库 GStringList类似于TStringList Autor: 不得闲 QQ:75492895

Package DxCommonLib

时间轮询调度池,只用一个定时器来实现After等超时设定,默认轮渡器设定为1个小时,精度为500毫秒 如果要使用更精确的定时器,请使用NewTimeWheelWorker自己指定定时器时间,目前在我的电脑上测试来看,最精确能到2毫秒 Author: 不得闲 QQ:75492895

公用包 Autor: 不得闲 QQ:75492895

Index

Constants

View Source
const (
	MinsPerHour = 60
	MinsPerDay  = 24 * MinsPerHour
	SecsPerDay  = MinsPerDay * 60
	MSecsPerDay = SecsPerDay * 1000
)

Variables

View Source
var (
	IsAmd64                = runtime.GOARCH == "amd64"
	ErrInvalidJsonDateTime = errors.New("invalidate json dateTime format")
)
View Source
var (
	EINVAL = errors.New("invalid argument")
)

Functions

func After

func After(d time.Duration) <-chan struct{}

func AfterFunc

func AfterFunc(d time.Duration, aFunc GWorkerFunc)

func Bin2Hex added in v0.1.8

func Bin2Hex(bt []byte) string

func Binary2Hex

func Binary2Hex(bt []byte, dst []byte) []byte

Binary2Hex 2进制转到16进制

func Buffer2ByteSlice added in v0.3.4

func Buffer2ByteSlice(Data uintptr, DataLen int) []byte

Buffer2ByteSlice 返回值不能修改

func ByteSliceIsPrintString added in v0.3.4

func ByteSliceIsPrintString(Data []byte, scanStyle byte) bool

ByteSliceIsPrintString 判断二进制数组是否是可打印的字符串,如果打印字符的的百分比超过了指定的printPercent, 认为是可显示的Plaintext scanStyle 0 表示全扫描,1表示扫描头部10个rune,2表示扫描两头,3表示扫描前中尾

func CanConvertStructField added in v0.5.0

func CanConvertStructField(field1, field2 *reflect.StructField) bool

CanConvertStructField field1->是否能够 匹配field2字段

func CanKeyMatchStructField added in v0.5.0

func CanKeyMatchStructField(key string, field *reflect.StructField) bool

CanKeyMatchStructField key是否匹配field

func CompareMem

func CompareMem(a, b unsafe.Pointer, size int) bool

CompareMem 内存比较函数

func CopyMemory

func CopyMemory(to, from unsafe.Pointer, n uintptr)

CopyMemory 内存拷贝函数

func DelphiStringLen added in v0.5.2

func DelphiStringLen(delphiString uintptr) (result int32)

DelphiStringLen 获取Delphi字符串的长度

func EscapeJsonStr

func EscapeJsonStr(str string, EscapeUnicode bool) string

EscapeJsonStr 将内容转义成Json字符串

func EscapeJsonbyte added in v0.1.8

func EscapeJsonbyte(str string, EscapeUnicode bool, dst []byte) []byte

func FastByte2String

func FastByte2String(bt []byte) string

func FastBytes2Uint16s

func FastBytes2Uint16s(bt []byte) []uint16

func FastDelphiString2String added in v0.5.2

func FastDelphiString2String(delphiString uintptr, unicodeDelphi bool) string

FastDelphiString2String 将Delphi的字符串转为Go字符串 因为实际上Delphi的字符串,就是一个指针,这个指针的指向是数据位置,-4位置是长度,-8位置是引用计数,-10位置是每个字符占位个数,-12位置表示的是CodePage编码页 以上是对Unicode的Delphi的,如果是DXE之后的版本就只有到-8,有长度和引用计数,后面的都没有

func FastPByte2ByteSlice added in v0.3.2

func FastPByte2ByteSlice(pByte uintptr, byteLen int) []byte

func FastPchar2String

func FastPchar2String(pcharStr uintptr) string

func FastString2Byte

func FastString2Byte(str string) []byte

FastString2Byte 本函数只作为强制转换使用,不可将返回的Slice再做修改处理

func FastString2Utf16Byte added in v0.2.5

func FastString2Utf16Byte(s string) ([]byte, error)

func GBK2Utf8

func GBK2Utf8(gbk []byte) ([]byte, error)

func GBKString

func GBKString(str string) ([]byte, error)

func Hex2Binary

func Hex2Binary(hexStr string) []byte

Hex2Binary 16进制到2进制

func IsSimpleCopyKind added in v0.5.0

func IsSimpleCopyKind(kind reflect.Kind) bool

IsSimpleCopyKind 是否是简单的可copy的类型

func ModePermStr2FileMode

func ModePermStr2FileMode(permStr string) (result os.FileMode)

ModePermStr2FileMode 将drwxrwx这些转化为 FileMode

func MustPostFunc added in v0.5.3

func MustPostFunc(routineFunc GWorkerFunc, params ...interface{})

func MustRunAsync added in v0.1.8

func MustRunAsync(routineFunc GWorkerFunc, params ...interface{})

MustRunAsync 必须异步执行到

func Ord

func Ord(x bool) uint8

func ParseFloat added in v0.2.5

func ParseFloat(s string) (float64, error)

func ParseInt64 added in v0.2.5

func ParseInt64(s string) (int64, error)

func ParseStructTag added in v0.5.0

func ParseStructTag(tag string) map[string]string

ParseStructTag 后续可以缓存起来

func ParserEscapeStr

func ParserEscapeStr(bvalue []byte, unEscapeUrl bool, buf []byte) string

ParserEscapeStr 解码转义字符,将"\u6821\u56ed\u7f51\t02%20得闲"这类字符串,解码成正常显示的字符串

func ParserJsonTime

func ParserJsonTime(jsontime string) (time.Time, error)

ParserJsonTime Date(1402384458000) Date(1224043200000+0800)

func ParserJsonTime2Go added in v0.1.8

func ParserJsonTime2Go(jsontime string) time.Time

ParserJsonTime2Go Date(1402384458000) Date(1224043200000+0800)

func Pchar2String

func Pchar2String(pcharstr uintptr) string

Pchar2String 将常规的pchar返回到string

func PcharLen

func PcharLen(dstr uintptr) int

func PostFunc

func PostFunc(routineFunc GWorkerFunc, params ...interface{}) bool

func ReSetDefaultTimeWheel

func ReSetDefaultTimeWheel(Chkinterval time.Duration, slotBlockCount int32)

func ReadAll added in v0.2.8

func ReadAll(r io.Reader) ([]byte, error)

func ResetDefaultWorker added in v0.1.8

func ResetDefaultWorker(maxGoroutinesAmount int, maxGoroutineIdleDuration time.Duration)

func Sleep

func Sleep(d time.Duration)

func StopWorkers

func StopWorkers()

func StrToFloatDef added in v0.1.8

func StrToFloatDef(s string, defv float64) float64

StrToFloatDef github.com/valyala/fastjson/tree/master/fastfloat

func StrToIntDef added in v0.1.8

func StrToIntDef(vstr string, defv int64) int64

StrToIntDef From github.com/valyala/fastjson/tree/master/fastfloat

func StrToUintDef added in v0.1.8

func StrToUintDef(vstr string, defv uint64) uint64

StrToUintDef From github.com/valyala/fastjson/tree/master/fastfloat

func String2Utf16Byte added in v0.2.5

func String2Utf16Byte(s string) ([]byte, error)

func StringData added in v0.3.4

func StringData(str string) (uintptr, int)

func StringFromUtf16Pointer added in v0.1.4

func StringFromUtf16Pointer(utf16Addr uintptr, maxlen int) string

func TryPostAndRun added in v0.1.8

func TryPostAndRun(routineFunc GWorkerFunc, params ...interface{})

func UTF16Byte2string

func UTF16Byte2string(utf16bt []byte, isBigEnd bool) string

func UTF16FromString added in v0.2.5

func UTF16FromString(s string) ([]uint16, error)

func UnEscapeStr added in v0.1.8

func UnEscapeStr(bvalue []byte, unEscapeUrl bool, buf []byte) []byte

func Utf8String added in v0.3.4

func Utf8String(utf8Data uintptr, utf8Len int) string

Utf8String 此函数的返回值不能修改

func ZeroByteSlice

func ZeroByteSlice(bt []byte)

func ZeroMemory

func ZeroMemory(ptr unsafe.Pointer, n uintptr)

ZeroMemory 清空内存

Types

type DxBits

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

DxBits 用来存放位

func (*DxBits) AsInt32

func (bt *DxBits) AsInt32() int32

func (*DxBits) AsInt64

func (bt *DxBits) AsInt64() int64

func (*DxBits) AsUInt32

func (bt *DxBits) AsUInt32() uint32

func (*DxBits) AsUInt64

func (bt *DxBits) AsUInt64() uint64

func (*DxBits) Bits

func (bt *DxBits) Bits(index uint) bool

func (*DxBits) CheckedCount

func (bt *DxBits) CheckedCount() uint

CheckedCount 选中的位的个数

func (*DxBits) Clear

func (bt *DxBits) Clear()

func (*DxBits) Count

func (bt *DxBits) Count() uint

func (*DxBits) NotBits

func (bt *DxBits) NotBits(index int)

NotBits 将指定的位取反,如果指定的位为-1,则将全部的位各自取反,1变0,0变1

func (*DxBits) ReSet

func (bt *DxBits) ReSet(bsize uint)

ReSet 重置

func (*DxBits) ReSetByInt32

func (bt *DxBits) ReSetByInt32(v int32)

func (*DxBits) ReSetByInt64

func (bt *DxBits) ReSetByInt64(v int64)

func (*DxBits) SetBits

func (bt *DxBits) SetBits(index uint, v bool)

type DxRingBuffer added in v0.1.6

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

func NewRingBuffer added in v0.1.6

func NewRingBuffer(size int) *DxRingBuffer

func (*DxRingBuffer) Capacity added in v0.1.6

func (buffer *DxRingBuffer) Capacity() int

func (*DxRingBuffer) DataSize added in v0.1.6

func (buffer *DxRingBuffer) DataSize() int

DataSize 数据长度

func (*DxRingBuffer) FreeSize added in v0.1.6

func (buffer *DxRingBuffer) FreeSize() int

FreeSize 剩下的空余大小

func (*DxRingBuffer) IsEmpty added in v0.1.6

func (buffer *DxRingBuffer) IsEmpty() bool

func (*DxRingBuffer) IsFull added in v0.1.6

func (buffer *DxRingBuffer) IsFull() bool

func (*DxRingBuffer) MarkReadWrite added in v0.1.6

func (buffer *DxRingBuffer) MarkReadWrite()

func (*DxRingBuffer) Read added in v0.1.6

func (buffer *DxRingBuffer) Read(p []byte) (n int, err error)

func (*DxRingBuffer) ReadByte added in v0.1.6

func (buffer *DxRingBuffer) ReadByte() (b byte, err error)

func (*DxRingBuffer) Reset added in v0.1.6

func (buffer *DxRingBuffer) Reset()

func (*DxRingBuffer) RestoreMark added in v0.1.6

func (buffer *DxRingBuffer) RestoreMark()

func (*DxRingBuffer) Skip added in v0.1.6

func (buffer *DxRingBuffer) Skip(n int)

func (*DxRingBuffer) Write added in v0.1.6

func (buffer *DxRingBuffer) Write(p []byte) (n int, err error)

func (*DxRingBuffer) WriteByte added in v0.1.6

func (buffer *DxRingBuffer) WriteByte(b byte)

type FileCodeMode

type FileCodeMode uint8 //文件格式
const (
	File_Code_Unknown FileCodeMode = iota
	File_Code_Utf8
	File_Code_Utf16BE
	File_Code_Utf16LE
	File_Code_GBK
)

type FileOpenMode

type FileOpenMode int //文件打开方式
const (
	FMCreate        FileOpenMode = FileOpenMode(os.O_CREATE | os.O_WRONLY | os.O_TRUNC)
	FMOpenRead      FileOpenMode = FileOpenMode(os.O_RDONLY)
	FMOpenWrite     FileOpenMode = FileOpenMode(os.O_WRONLY) // | os.O_APPEND)
	FMOpenReadWrite FileOpenMode = FileOpenMode(os.O_RDWR)   // | os.O_APPEND)

)

type GDxBaseObject

type GDxBaseObject struct {
	UseData interface{} //用户数据
	// contains filtered or unexported fields
}

func (*GDxBaseObject) Destroy

func (obj *GDxBaseObject) Destroy()

func (*GDxBaseObject) Free

func (obj *GDxBaseObject) Free()

func (*GDxBaseObject) LastedSubChild

func (obj *GDxBaseObject) LastedSubChild() interface{}

func (*GDxBaseObject) SubChild

func (obj *GDxBaseObject) SubChild(idx int) interface{}

func (*GDxBaseObject) SubChildCount

func (obj *GDxBaseObject) SubChildCount() int

func (*GDxBaseObject) SubInit

func (obj *GDxBaseObject) SubInit(subObj interface{})

type GFileStream

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

func NewFileStream

func NewFileStream(fileName string, openMode FileOpenMode, bufferSize int) (*GFileStream, error)

func (*GFileStream) Close

func (stream *GFileStream) Close()

func (*GFileStream) FilePosition

func (stream *GFileStream) FilePosition() int64

func (*GFileStream) FlushBuffer

func (stream *GFileStream) FlushBuffer() error

func (*GFileStream) Position

func (stream *GFileStream) Position() int

func (*GFileStream) Read

func (stream *GFileStream) Read(buffer []byte) (n int, err error)

func (*GFileStream) ReadAt

func (stream *GFileStream) ReadAt(p []byte, off int64) (n int, err error)

ReadAt ReaderAt interface

func (*GFileStream) ReadByte

func (stream *GFileStream) ReadByte() (byte, error)

ReadByte ByteReader

func (*GFileStream) ReadFrom

func (stream *GFileStream) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom interface

func (*GFileStream) Seek

func (stream *GFileStream) Seek(offset int64, whence int) (int64, error)

func (*GFileStream) SetPosition

func (stream *GFileStream) SetPosition(ps int) error

func (*GFileStream) Size

func (stream *GFileStream) Size() int64

func (*GFileStream) UnreadByte

func (stream *GFileStream) UnreadByte() error

func (*GFileStream) Write

func (stream *GFileStream) Write(data []byte) (int, error)

func (*GFileStream) WriteAt

func (stream *GFileStream) WriteAt(p []byte, off int64) (n int, err error)

WriteAt WriterAt interface

func (*GFileStream) WriteByte

func (stream *GFileStream) WriteByte(c byte) error

func (*GFileStream) WriteTo

func (stream *GFileStream) WriteTo(w io.Writer) (n int64, err error)

WriteTo interface

type GStringList

type GStringList struct {
	LineBreak         LineBreakMode
	UnknownCodeUseGbk bool //未知编码的时候采用GBK编码打开
	// contains filtered or unexported fields
}

func (*GStringList) Add

func (lst *GStringList) Add(str string)

func (*GStringList) AddPair

func (lst *GStringList) AddPair(Name, Value string)

func (*GStringList) AddSlice

func (lst *GStringList) AddSlice(strs []string)

func (*GStringList) AddStrings

func (lst *GStringList) AddStrings(strs IStrings)

func (*GStringList) AsSlice

func (lst *GStringList) AsSlice() []string

func (*GStringList) Clear

func (lst *GStringList) Clear()

func (*GStringList) Count

func (lst *GStringList) Count() int

func (*GStringList) Delete

func (lst *GStringList) Delete(index int)

func (*GStringList) IndexOf

func (lst *GStringList) IndexOf(str string) int

func (*GStringList) IndexOfName

func (lst *GStringList) IndexOfName(Name string) int

func (*GStringList) Insert

func (lst *GStringList) Insert(Index int, str string)

func (*GStringList) LineBreakStr

func (lst *GStringList) LineBreakStr() string

func (*GStringList) LoadFromFile

func (lst *GStringList) LoadFromFile(fileName string)

func (*GStringList) LoadFromReader added in v0.1.5

func (lst *GStringList) LoadFromReader(r io.Reader, filecodeType FileCodeMode)

func (*GStringList) Names

func (lst *GStringList) Names(Index int) string

func (*GStringList) SaveToFile

func (lst *GStringList) SaveToFile(fileName string)

func (*GStringList) SetStrings

func (lst *GStringList) SetStrings(index int, str string)

func (*GStringList) SetText

func (lst *GStringList) SetText(text string)

func (*GStringList) Strings

func (lst *GStringList) Strings(index int) string

func (*GStringList) Text

func (lst *GStringList) Text() string

func (*GStringList) ValueByName

func (lst *GStringList) ValueByName(Name string) string

func (*GStringList) ValueFromIndex

func (lst *GStringList) ValueFromIndex(index int) string

type GWorkerFunc

type GWorkerFunc func(data ...interface{})

type GWorkers

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

func NewWorkers

func NewWorkers(maxGoroutinesAmount int, maxGoroutineIdleDuration time.Duration) *GWorkers

func (*GWorkers) MustPostFunc added in v0.5.3

func (workers *GWorkers) MustPostFunc(routineFunc GWorkerFunc, params ...interface{})

MustPostFunc 必然投递

func (*GWorkers) MustRunAsync added in v0.1.8

func (workers *GWorkers) MustRunAsync(routineFunc GWorkerFunc, params ...interface{})

MustRunAsync 必须异步执行到

func (*GWorkers) PostFunc

func (workers *GWorkers) PostFunc(routineFunc GWorkerFunc, params ...interface{}) bool

func (*GWorkers) Start

func (workers *GWorkers) Start()

func (*GWorkers) Stop

func (workers *GWorkers) Stop()

func (*GWorkers) TryPostAndRun added in v0.1.8

func (workers *GWorkers) TryPostAndRun(routineFunc GWorkerFunc, params ...interface{})

type IDxInheritedObject

type IDxInheritedObject interface {
	SubChild(idx int) interface{}
	SubChildCount() int
	Destroy()
	SubInit()
	LastedSubChild() interface{} //最后一个继承者
}

type IStrings

type IStrings interface {
	Count() int
	Strings(index int) string
	SetStrings(index int, str string)
	Text() string
	SetText(text string)
	LoadFromFile(fileName string)
	SaveToFile(fileName string)
	Add(str string)
	Insert(Index int, str string)
	Delete(index int)
	AddStrings(strs IStrings)
	AddSlice(strs []string)
	Clear()
	IndexOf(str string) int

	AddPair(Name, Value string)
	IndexOfName(Name string) int
	ValueFromIndex(index int) string
	ValueByName(Name string) string
	Names(Index int) string
	AsSlice() []string
}

type LineBreakMode

type LineBreakMode byte
const (
	LBK_CRLF LineBreakMode = iota
	LBK_CR
	LBK_LF
)

type TDateTime

type TDateTime float64

func Time2DelphiTime

func Time2DelphiTime(t time.Time) TDateTime

func (TDateTime) ToTime

func (date TDateTime) ToTime() time.Time

ToTime 从Delphi日期转为Go日期格式 Delphi的日期规则为到1899-12-30号的天数+当前的毫秒数/一天的总共毫秒数集合

func (*TDateTime) WrapTime2Self

func (date *TDateTime) WrapTime2Self(t time.Time)

type TimeWheelWorker

type TimeWheelWorker struct {
	sync.Mutex //调度锁
	// contains filtered or unexported fields
}

func NewTimeWheelWorker

func NewTimeWheelWorker(interval time.Duration, slotBlockCount int32) *TimeWheelWorker

NewTimeWheelWorker interval指定调度的时间间隔 slotBlockCount指定时间轮的块长度

func (*TimeWheelWorker) After

func (worker *TimeWheelWorker) After(d time.Duration) <-chan struct{}

func (*TimeWheelWorker) AfterFunc

func (worker *TimeWheelWorker) AfterFunc(d time.Duration, afterFunc GWorkerFunc, data ...interface{})

func (*TimeWheelWorker) Sleep

func (worker *TimeWheelWorker) Sleep(d time.Duration)

func (*TimeWheelWorker) Stop

func (worker *TimeWheelWorker) Stop()

Directories

Path Synopsis
* 并发共享函数调用返回的库
* 并发共享函数调用返回的库

Jump to

Keyboard shortcuts

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