DxCommonLib

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: MIT Imports: 21 Imported by: 5

Documentation

Overview

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

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

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

Functions

func After

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

func AfterFunc

func AfterFunc(d time.Duration, afunc func())

func Bin2Hex added in v0.1.8

func Bin2Hex(bt []byte) string

func Binary2Hex

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

2进制转到16进制

func CoarseTimeNow

func CoarseTimeNow() time.Time

func CompareMem

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

内存比较函数

func CopyMemory

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

内存拷贝函数

func DelphiPchar2String

func DelphiPchar2String(dstr uintptr) string

将Delphi的Pchar转换到string,Unicode

func DelphiPcharLen

func DelphiPcharLen(dstr uintptr) (result int32)

func EscapeJsonStr

func EscapeJsonStr(str string) string

将内容转义成Json字符串

func EscapeJsonbyte added in v0.1.8

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

func FastByte2String

func FastByte2String(bt []byte) string

func FastBytes2Uint16s

func FastBytes2Uint16s(bt []byte) []uint16

func FastDelphiPchar2String

func FastDelphiPchar2String(pcharstr uintptr) string

func FastPchar2String

func FastPchar2String(pcharstr uintptr) string

func FastString2Byte

func FastString2Byte(str string) []byte

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

func GBK2Utf8

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

func GBKString

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

func Hex2Binary

func Hex2Binary(hexStr string) []byte

16进制到2进制

func ModePermStr2FileMode

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

将drwxrwx这些转化为 FileMode

func MustRunAsync added in v0.1.8

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

必须异步执行到

func Ord

func Ord(x bool) uint8

func ParserEscapeStr

func ParserEscapeStr(bvalue []byte) string

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

func ParserJsonTime2Go added in v0.1.8

func ParserJsonTime2Go(jsontime string) time.Time

Date(1402384458000) Date(1224043200000+0800)

func Pchar2String

func Pchar2String(pcharstr uintptr) string

将常规的pchar返回到string

func PcharLen

func PcharLen(dstr uintptr) int

func Post

func Post(runner ITaskRunner)

func PostFunc

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

func ReSetDefaultTimeWheel

func ReSetDefaultTimeWheel(Chkinterval time.Duration, slotBlockCount int)

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

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

func StrToIntDef added in v0.1.8

func StrToIntDef(vstr string, defv int64) int64

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

func StrToUintDef added in v0.1.8

func StrToUintDef(vstr string, defv uint64) uint64

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

func StringFromUtf16Pointer added in v0.1.4

func StringFromUtf16Pointer(utf16Addr uintptr, maxlen int) string

func StringFromUtf8Pointer added in v0.1.4

func StringFromUtf8Pointer(utf8Addr uintptr, maxlen int) string

func TryPostAndRun added in v0.1.8

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

func UTF16Byte2string

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

func UnEscapeStr added in v0.1.8

func UnEscapeStr(bvalue []byte) []byte

func ZeroByteSlice

func ZeroByteSlice(bt []byte)

func ZeroMemory

func ZeroMemory(ptr unsafe.Pointer, n uintptr)

清空内存

Types

type DxBits

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

用来存放位

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

选中的位的个数

func (*DxBits) Clear

func (bt *DxBits) Clear()

func (*DxBits) Count

func (bt *DxBits) Count() uint

func (*DxBits) NotBits

func (bt *DxBits) NotBits(index int)

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

func (*DxBits) ReSet

func (bt *DxBits) ReSet(bsize uint)

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

数据长度

func (*DxRingBuffer) FreeSize added in v0.1.6

func (buffer *DxRingBuffer) FreeSize() int

剩下的空余大小

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)

ReaderAt interface

func (*GFileStream) ReadByte

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

ByteReader

func (*GFileStream) ReadFrom

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

ReaderFrom 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)

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)

WriterTo 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) MustRunAsync added in v0.1.8

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

必须异步执行到

func (*GWorkers) Post

func (workers *GWorkers) Post(runner ITaskRunner) bool

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{}) bool

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 ITaskRunner

type ITaskRunner interface {
	Run()
}

任务

type LineBreakMode

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

type TDateTime

type TDateTime float64

func ParserJsonTime

func ParserJsonTime(jsontime string) TDateTime

Date(1402384458000) Date(1224043200000+0800)

func Time2DelphiTime

func Time2DelphiTime(t time.Time) TDateTime

func (TDateTime) ToTime

func (date TDateTime) ToTime() time.Time

从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 int, tkfunc func()) *TimeWheelWorker

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

func (*TimeWheelWorker) After

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

func (*TimeWheelWorker) AfterFunc

func (worker *TimeWheelWorker) AfterFunc(d time.Duration, afunc func())

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