yx

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: BSD-2-Clause Imports: 29 Imported by: 10

README

yx

v0.1.1

Documentation

Index

Constants

View Source
const (
	BP_MIN_BUFF_SIZE = 64
	BP_MAX_BUFF_SIZE = 4 * 1024
	BP_QUEUE_STEP    = 64
)
View Source
const (
	LOG_BATCH_DUMP_COUNT       = 100
	LOG_MAX_CACHE_SIZE         = 64 * 1024
	LOG_DEFAULT_DUMP_SIZE      = 32 * 1024 * 1024
	LOG_DEFAULT_DUMP_THRESHOLD = 32 * 1024
	LOG_DEFAULT_DUMP_INTV      = 100

	LOG_STR_BUILD_INIT_CAP = 128
)
View Source
const LOG_DEBUG_SWITCH_FILE = "debug.sf"

Variables

View Source
var (
	ErrAesDataLenZero      = errors.New("data len is 0")
	ErrAesKeyLenZero       = errors.New("key len is 0")
	ErrAesUnpaddingTooMuch = errors.New("unpadding count more than data len")
)
View Source
var (
	ErrEcdsaDataLenZero     = errors.New("data len is 0")
	ErrEcdsaKeyLenZero      = errors.New("key len is 0")
	ErrEcdsaParsePubKeyFail = errors.New("parse public key failed")
)
View Source
var (
	ErrEvtWaitTimeout = errors.New("event wait time out")
	ErrEvtClosed      = errors.New("event closed")
)
View Source
var (
	ErrObjFactObjIsNil       = errors.New("object is nil")
	ErrObjFactWsExist        = errors.New("object workshop is exist")
	ErrObjFactWsNotExist     = errors.New("object workshop is not exist")
	ErrObjFactNotTheSameType = errors.New("not the same type")
)
View Source
var (
	ErrQueEmptyQueue = errors.New("empty queue")
	ErrQueFullQueue  = errors.New("full queue")
)
View Source
var (
	ErrRsaDataLenZero = errors.New("data len is 0")
	ErrRsaKeyLenZero  = errors.New("key len is 0")
)
View Source
var (
	ErrNoSpaceToRead = errors.New("no space to read data")
	ErrBuffEmpty     = errors.New("buffer empty")
	ErrReachEnd      = errors.New("buffer reach end")
)
View Source
var (
	ErrUtilObjIsNil    = errors.New("object is nil")
	ErrWrongTimeFormat = errors.New("wrong time format")
)
View Source
var (
	ErrCrc16DataLenZero = errors.New("data len is 0")
)
View Source
var (
	ErrIdGenIdUseOut = errors.New("id use out")
)
View Source
var (
	ErrMailIsNil = errors.New("mail is nil")
)

Functions

func AesDecrypt

func AesDecrypt(encrypted []byte, key []byte) ([]byte, error)

Aes decrypt. @param encrypted, data need to decrypt. @param key, aes decrypt key, either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256. @return []byte, original data. @return error, error.

func AesDecryptBase64

func AesDecryptBase64(encryptedBase64 string, keyBase64 string) ([]byte, error)

Aes decrypt with string key which encode by base64. @param encryptedBase64, data need to decrypt which encode by base64. @param keyBase64, aes decrypt key which encode by base64. @return []byte, original data. @return error, error.

func AesEncrypt

func AesEncrypt(origData []byte, key []byte) ([]byte, error)

Aes encrypt. @param origData, data need to encrypt. @param key, aes encrypt key, either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256. @return []byte, data encrypted. @return error, error.

func AesEncryptBase64

func AesEncryptBase64(origData []byte, keyBase64 string) (string, error)

Aes encrypt with string key which encode by base64. @param origData, data need to encrypt. @param keyBase64, aes encrypt key which encode by base64. @return string, data encrypted which encode by base64. @return error, error.

func ConfigLogger added in v0.1.5

func ConfigLogger(cfg *LogConf, printFunc func(lv LogLv, logStr string))

func Crc16CheckSum

func Crc16CheckSum(data []byte) (uint16, error)

Calculation check sum with CRC-16/MODBUS. @param data, data need to calculation check sum. @return uint16, the check sum. @return error, error.

func Daemon added in v0.3.0

func Daemon(program string, args []string, restartDelay uint16, shutdownFile string) error

func EcdsaGenerateKey added in v0.2.0

func EcdsaGenerateKey(ellType ElliptcType) (pubKey []byte, priKey []byte, err error)

func EcdsaGenerateKeyPem added in v0.2.0

func EcdsaGenerateKeyPem(ellType ElliptcType) (pemPubKey string, pemPriKey string, err error)

func EcdsaSign added in v0.2.0

func EcdsaSign(origData []byte, priKey []byte) ([]byte, []byte, error)

func EcdsaSignPem added in v0.2.0

func EcdsaSignPem(origData []byte, pemPriKey string) ([]byte, []byte, error)

func EcdsaVerify added in v0.2.0

func EcdsaVerify(origData []byte, rText []byte, sText []byte, pubKey []byte) (bool, error)

func EcdsaVerifyPem added in v0.2.0

func EcdsaVerifyPem(origData []byte, rText []byte, sText []byte, pemPubKey string) (bool, error)

func FormatInt added in v0.2.1

func FormatInt(num int64, maxLength uint32, bFillZero bool, builder *strings.Builder) string

Format integer. @param num, the number to format. @param maxLength, the max length in decimal. @param bFillZero, is fill zero to prefix. @param builder, a string builder. if not nil, only build string, not return @return string, the format string of time.

func FormatTimeStr added in v0.2.1

func FormatTimeStr(format string, t time.Time, builder *strings.Builder) (string, error)

Format the string of time. @param format, format of the string with YY MM DD hh mm ss. @param t, the time object to format. @param builder, a string builder. if not nil, only build string, not return @return string, the format string of time. @return error, the error

func FormatUint added in v0.2.1

func FormatUint(num uint64, maxLength uint32, bFillZero bool, builder *strings.Builder) string

Format unsigned integer. @param num, the number to format. @param maxLength, the max length in decimal. @param bFillZero, is fill zero to prefix. @param builder, a string builder. if not nil, only build string, not return @return string, the format string of time.

func GetClassName added in v0.1.6

func GetClassName(classReflectName string) string

func GetClassReflectName added in v0.1.6

func GetClassReflectName(obj interface{}) (string, error)

func GetFilePackageClassName added in v0.1.6

func GetFilePackageClassName(classReflectName string) string

func GetFilePackageName added in v0.1.6

func GetFilePackageName(fullPackName string) string

func GetFileSize

func GetFileSize(path string) (int64, error)

Get the size of file. @param path, the file path. @return int64, the size. @return error, error.

func GetFullPackageName added in v0.1.6

func GetFullPackageName(classReflectName string) string

func GetReflectNameByType added in v0.1.12

func GetReflectNameByType(t reflect.Type) string

func IsFileExist

func IsFileExist(path string) (bool, error)

Is the file exist. @param path, the file path. @return bool, if error is nil, true mean exist, false mean not exist. @return error, error.

func LoadJsonConf added in v0.1.2

func LoadJsonConf(v interface{}, path string, decodeCb func(data []byte) ([]byte, error)) error

Load config from a json file. @param v, config object. @param path, path of the json file. @param decodeCb, a callback function to decode the content of the file. @return error, error.

func LogArgs added in v0.3.6

func LogArgs(a ...interface{}) []interface{}

func PKCS7Padding

func PKCS7Padding(origData []byte, blockSize int) []byte

func PKCS7Unpadding

func PKCS7Unpadding(decrypted []byte) ([]byte, error)

func PowerOfTen added in v0.2.1

func PowerOfTen(power uint32) uint64

Get the power of ten. @param power, the power. @return uint64, the result

func ProtectRun

func ProtectRun(entry func())

Protect run, if panic, it will recover. @param entry, the function of danger code.

func Random added in v0.3.2

func Random(min int, max int) int

return a non-negative pseudo-random number in [min,max) from the default Source. It panics if max <= min.

func RandomIntn added in v0.3.2

func RandomIntn(n int) int

return a non-negative pseudo-random number in [0,n) from the default Source. It panics if n <= 0.

func RsaDecrypt added in v0.2.0

func RsaDecrypt(encrypted []byte, priKey []byte) ([]byte, error)

func RsaDecryptPem added in v0.2.0

func RsaDecryptPem(encrypted []byte, pemPriKey string) ([]byte, error)

func RsaEncrypt added in v0.2.0

func RsaEncrypt(origData []byte, pubKey []byte) ([]byte, error)

func RsaEncryptPem added in v0.2.0

func RsaEncryptPem(origData []byte, pemPubKey string) ([]byte, error)

func RsaGenerateKey added in v0.2.0

func RsaGenerateKey(bits int) (pubKey []byte, priKey []byte, err error)

func RsaGenerateKeyPem added in v0.2.0

func RsaGenerateKeyPem(bits int) (pemPubKey string, pemPriKey string, err error)

func RsaSign added in v0.2.0

func RsaSign(origData []byte, priKey []byte) ([]byte, error)

func RsaSignPem added in v0.2.0

func RsaSignPem(origData []byte, pemPriKey string) ([]byte, error)

func RsaVerify added in v0.2.0

func RsaVerify(origData []byte, signData []byte, pubKey []byte) (bool, error)

func RsaVerifyPem added in v0.2.0

func RsaVerifyPem(origData []byte, signData []byte, pemPubKey string) (bool, error)

func RunDangerCode

func RunDangerCode(entry func(), bDebugMode bool)

Run danger code. @param entry, the function of danger code. @param bDebugMode, true will run in normal mode, false will run in protect mode.

func SendMail

func SendMail(m *Mail) error

Send a mail. @param m, the mail to send. @return error, error.

func SetLogLevel

func SetLogLevel(lv LogLv)

Set log level. @param lv, the level to begin print.

func SetPrintFunc added in v0.3.2

func SetPrintFunc(printFunc func(lv LogLv, logStr string))

Set a new print func to instead of the default one. eg: PowerShell print.

var (

kernel32                *syscall.LazyDLL  = syscall.NewLazyDLL(`kernel32.dll`)
SetConsoleTextAttribute *syscall.LazyProc = nil
CloseHandle             *syscall.LazyProc = nil
BgColor   int   = 0x50
FontColor Color = Color{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf}

)

type Color struct {
	black        int
	blue         int
	green        int
	cyan         int
	red          int
	purple       int
	yellow       int
	light_gray   int
	gray         int
	light_blue   int
	light_green  int
	light_cyan   int
	light_red    int
	light_purple int
	light_yellow int
	white        int
}
func PowerShellPrint(lv yx.LogLv, logStr string) {
	if SetConsoleTextAttribute == nil {
		SetConsoleTextAttribute = kernel32.NewProc(`SetConsoleTextAttribute`)
	}

	if CloseHandle == nil {
		CloseHandle = kernel32.NewProc(`CloseHandle`)
	}

	color := FontColor.white
	if lv == yx.LOG_LV_ERROR {
		color = FontColor.light_red
	} else if lv == yx.LOG_LV_WARN {
		color = FontColor.light_yellow
	}

	handle, _, _ := SetConsoleTextAttribute.Call(uintptr(syscall.Stdout), uintptr(BgColor|color))
	fmt.Print(logStr)
	CloseHandle.Call(handle)
}

func StartDumpLog

func StartDumpLog(file string, dumpFileSize int, dumpThreshold int, dumpIntervalMs uint32)

Start dump log. @param file, the relative/full path of a file. @param dumpFileSize, max size of the dump file. @param dumpThreshold, max count of logs in buffer to cause dump. @param dumpIntervalMs, dump interval in millisecond.

func StartDumpLogDefault

func StartDumpLogDefault(file string)

Start dump log by default params. @param file, the relative/full path of a file.

func StartLogger added in v0.1.4

func StartLogger()

========================

global method

========================

func StopDumpLog

func StopDumpLog()

Stop dump log.

func StopLogger added in v0.1.4

func StopLogger()

Types

type AsyncDispatcher

type AsyncDispatcher struct {
	*BaseDispatcher
	// contains filtered or unexported fields
}

=====================================================

AsyncDispatcher

=====================================================

func NewAsyncDispatcher

func NewAsyncDispatcher(msgName string, maxMsgBuffSize uint16) *AsyncDispatcher

func (*AsyncDispatcher) Notify

func (d *AsyncDispatcher) Notify(params ...interface{})

func (*AsyncDispatcher) Start

func (d *AsyncDispatcher) Start()

func (*AsyncDispatcher) Stop

func (d *AsyncDispatcher) Stop()

type BaseDispatcher

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

=====================================================

BaseDispatcher

=====================================================

func NewBaseDispatcher

func NewBaseDispatcher(msgName string) *BaseDispatcher

func (*BaseDispatcher) AddObserver

func (d *BaseDispatcher) AddObserver(o Observer)

func (*BaseDispatcher) GetMsgName

func (d *BaseDispatcher) GetMsgName() string

func (*BaseDispatcher) Notify

func (d *BaseDispatcher) Notify(params ...interface{})

func (*BaseDispatcher) RemoveObserver

func (d *BaseDispatcher) RemoveObserver(o Observer)

type BuffFactory added in v0.1.13

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

func NewBuffFactory added in v0.1.13

func NewBuffFactory() *BuffFactory

func (*BuffFactory) CreateBuff added in v0.1.13

func (p *BuffFactory) CreateBuff(size uint32) *[]byte

func (*BuffFactory) ReuseBuff added in v0.1.13

func (p *BuffFactory) ReuseBuff(buffRef *[]byte)

type BuffPool added in v0.1.9

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

func NewBuffPool added in v0.1.9

func NewBuffPool(buffSize uint32) *BuffPool

func (*BuffPool) Get added in v0.1.13

func (p *BuffPool) Get() *[]byte

func (*BuffPool) Put added in v0.1.13

func (p *BuffPool) Put(buffRef *[]byte)

type Dispatcher

type Dispatcher interface {
	// Add an observer to the dispatcher.
	// @param o, the observer to be added.
	AddObserver(o Observer)

	// Remove an observer from the dispatcher.
	// @param o, the observer to be removed.
	RemoveObserver(o Observer)

	// Notify message.
	// @param params, the params of the message.
	Notify(params ...interface{})
}

type ElliptcType added in v0.2.0

type ElliptcType int
const (
	ELLIPTIC_TYPE_P521 ElliptcType = iota
	ELLIPTIC_TYPE_P384
	ELLIPTIC_TYPE_P256
	ELLIPTIC_TYPE_P224
)

type ErrCatcher

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

func NewErrCatcher

func NewErrCatcher(className string) *ErrCatcher

func (*ErrCatcher) Catch

func (c *ErrCatcher) Catch(methodName string, errRef *error)

Catch error. @param methodName, the name of method which catch the error. @param errRef, reference of an error.

func (*ErrCatcher) DeferThrow

func (c *ErrCatcher) DeferThrow(methodName string, errRef *error)

Throw error with defer. @param methodName, the name of method which throw the error. @param errRef, reference of an error.

func (*ErrCatcher) Throw

func (c *ErrCatcher) Throw(methodName string, err error) error

Throw error. @param methodName, the name of method which throw the error. @param err, an error. @return error, return the same error of param err.

func (*ErrCatcher) TryCodeFunc added in v0.3.1

func (c *ErrCatcher) TryCodeFunc(methodName string, f func() (int32, error)) (int32, error)

func (*ErrCatcher) TryFunc added in v0.3.1

func (c *ErrCatcher) TryFunc(methodName string, f func() error) error

type Event

type Event struct {
	C chan byte
	// contains filtered or unexported fields
}

func NewEvent

func NewEvent() *Event

func (*Event) Close

func (e *Event) Close()

Close the event.

func (*Event) Send

func (e *Event) Send() error

Send event.

func (*Event) Wait

func (e *Event) Wait() error

Wait event.

func (*Event) WaitUntilTimeout

func (e *Event) WaitUntilTimeout(timeoutMSec uint32) error

Wait event until timeout. @param timeoutMSec, timeout after millisecond. 0 mean check at once, only can use in one waiter scene. @return error, ErrEvtWaitTimeout mean timeout.

type IdGenerator

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

func NewIdGenerator

func NewIdGenerator(min uint64, max uint64) *IdGenerator

func (*IdGenerator) GetId

func (g *IdGenerator) GetId() (uint64, error)

Assign an id. @return uint64, the assign id. @return error, ErrIdGenIdUseOut mean use out.

func (*IdGenerator) ReuseId

func (g *IdGenerator) ReuseId(id uint64)

Reuse an id. @param id, the reuse id.

type InvokeInfo

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

func NewInvokeInfo

func NewInvokeInfo(className string, methodName string) *InvokeInfo

type InvokeStack

type InvokeStack = []*InvokeInfo

type LinkedQueue

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

========================

LinkedQueue

========================

func NewLinkedQueue

func NewLinkedQueue() *LinkedQueue

func (*LinkedQueue) Dequeue

func (q *LinkedQueue) Dequeue() (interface{}, error)

func (*LinkedQueue) Enqueue

func (q *LinkedQueue) Enqueue(item interface{}) error

func (*LinkedQueue) GetSize

func (q *LinkedQueue) GetSize() uint64

type LinkedQueueNode

type LinkedQueueNode struct {
	Data interface{}
	Next *LinkedQueueNode
}

========================

LinkedQueueNode

========================

func NewLinkedQueueNode

func NewLinkedQueueNode(data interface{}) *LinkedQueueNode

type LogConf added in v0.1.5

type LogConf struct {
	Level int `json:"level"`
	// IsPowerShellRun bool   `json:"power_shell_run"`
	IsDump        bool   `json:"is_dump"`
	DumpPath      string `json:"dump_path"`
	DumpFileSize  int    `json:"dump_file_size"`
	DumpThreshold int    `json:"dump_threshold"`
	DumpInterval  uint32 `json:"dump_interval"`
}

========================

log config

========================

type LogInfo added in v0.1.4

type LogInfo struct {
	Lv       LogLv
	Tag      string
	Args     []interface{}
	IsDetail bool
}

==============================================

logger

==============================================

type LogLv

type LogLv = int
const (
	LOG_LV_DEBUG LogLv = 0
	LOG_LV_INFO  LogLv = 1
	LOG_LV_WARN  LogLv = 2
	LOG_LV_ERROR LogLv = 3
)

type Logger

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

========================

Logger

========================

func NewLogger

func NewLogger(tag string) *Logger

func (*Logger) D

func (l *Logger) D(a ...interface{})

Print debug log.

func (*Logger) Detail

func (l *Logger) Detail(lv LogLv, logs [][]interface{})

Print detail log.

func (*Logger) E

func (l *Logger) E(a ...interface{})

Print error log.

func (*Logger) I

func (l *Logger) I(a ...interface{})

Print infomation log.

func (*Logger) W

func (l *Logger) W(a ...interface{})

Print warn log.

type Mail

type Mail struct {
	User      string
	AliasName string
	Pwd       string
	Host      string
	Port      int
	To        []string
	Subject   string
	Body      string
}

type NotifyCenter

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

=====================================================

NotifyCenter

=====================================================

func NewNotifyCenter

func NewNotifyCenter() *NotifyCenter

func (*NotifyCenter) AddDispatcher

func (c *NotifyCenter) AddDispatcher(msgName string, dispatcher Dispatcher)

Add an dispatcher to the notify center. @param msgName, the name of message which the dispatcher will notify. @param dispatcher, the dispatcher to be added.

func (*NotifyCenter) AddObserver

func (c *NotifyCenter) AddObserver(msgName string, o Observer)

Add an observer to the notify center. @param msgName, the name of message which the observer will listen to. @param o, the observer to be added.

func (*NotifyCenter) GetDispatcher

func (c *NotifyCenter) GetDispatcher(msgName string) (Dispatcher, bool)

Get an dispatcher from the notify center. @param msgName, the name of message which the dispatcher is notify. @return Dispatcher, the dispatcher @return bool, true mean success, false mean failed

func (*NotifyCenter) Notify

func (c *NotifyCenter) Notify(msgName string, params ...interface{})

Notify message. @param msgName, the name of message. @param params, the params of the message.

func (*NotifyCenter) RemoveDispatcher

func (c *NotifyCenter) RemoveDispatcher(msgName string)

Remove an dispatcher from the notify center. @param msgName, the name of message which the dispatcher is notify.

func (*NotifyCenter) RemoveObserver

func (c *NotifyCenter) RemoveObserver(msgName string, o Observer)

Remove an observer from the notify center. @param msgName, the name of message which the observer listening to. @param o, the observer to be removed.

type NotifyMsg

type NotifyMsg struct {
	Name   string
	Params []interface{}
}

type ObjectFactory added in v0.1.3

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

=========================

ObjectFactory

=========================

func NewObjectFactory added in v0.1.3

func NewObjectFactory() *ObjectFactory

func (*ObjectFactory) CreateObject added in v0.1.3

func (f *ObjectFactory) CreateObject(name string) (interface{}, error)

create an object by the name. @param name, the name. @return interface{}, the object is created. @return error, the error.

func (*ObjectFactory) GetReflectType added in v0.1.3

func (f *ObjectFactory) GetReflectType(name string) (reflect.Type, bool)

Get reflect type by the name. @param name, the name. @return reflect.Type, the reflect type. @return bool, true mean success, false mean failed.

func (*ObjectFactory) RegisterObject added in v0.1.3

func (f *ObjectFactory) RegisterObject(obj interface{}, newFunc func() interface{}, maxPoolCapacity uint64) (string, error)

Register object. @param obj, the reuseabe object. @param initReuseCnt, the init count in the pool. @param maxPoolCapacity, the max count in the pool. @return error, the error.

func (*ObjectFactory) ReuseObject added in v0.1.3

func (f *ObjectFactory) ReuseObject(v interface{}, name string) error

reuse an object by the name. @param v, the object. @param name, the name. @return error, the error.

type Observer

type Observer interface {
	// Callback when dispatcher notify message.
	// @param msg, the message notifying.
	OnNotify(msg *NotifyMsg)
}

type Queue

type Queue interface {
	// Enqueue.
	// @param item, item to enqueue.
	// @return error, error.
	Enqueue(item interface{}) error

	// Dequeue.
	// @return interface{}, dequeue item.
	// @return error, error.
	Dequeue() (interface{}, error)

	// Get queue size.
	// @return uint64, queue size.
	GetSize() uint64
}

========================

Queue

========================

type Set

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

func NewSet

func NewSet(t SetType) *Set

func (*Set) Add

func (s *Set) Add(data interface{})

Add item. @param data, the item to add

func (*Set) Exist

func (s *Set) Exist(data interface{}) bool

Is the item exist. @return bool, true exist, false not exist.

func (*Set) GetElements

func (s *Set) GetElements() []interface{}

Get all items. @return []interface{}, all item array.

func (*Set) GetSize

func (s *Set) GetSize() int

Get set size. @return int, the set size.

func (*Set) Pop

func (s *Set) Pop() (interface{}, bool)

Pop an items. @return interface{}, a random item. @return bool, true mean success, false mean failed.

func (*Set) Remove

func (s *Set) Remove(data interface{})

Remove item. @param data, the item to remove

type SetType

type SetType = uint8
const (
	SET_TYPE_INT SetType = iota
	SET_TYPE_UINT
	SET_TYPE_FLOAT
	SET_TYPE_OBJ
)

type SimpleBuffer

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

func NewSimpleBuffer

func NewSimpleBuffer(capacity int) *SimpleBuffer

func (*SimpleBuffer) GetData

func (buff *SimpleBuffer) GetData() []byte

Get the data. @return []byte, the data.

func (*SimpleBuffer) GetDataLen

func (buff *SimpleBuffer) GetDataLen() int

Get the length of data. @return int, the length of data.

func (*SimpleBuffer) GetWriteBuff

func (buff *SimpleBuffer) GetWriteBuff() []byte

Get the write buffer. @return []byte, the write buffer.

func (*SimpleBuffer) GetWriteBuffSize

func (buff *SimpleBuffer) GetWriteBuffSize() int

Get the size of write buffer. @return int, the size of write buffer.

func (*SimpleBuffer) MoveDataToBegin

func (buff *SimpleBuffer) MoveDataToBegin()

Move the data to offset = 0.

func (*SimpleBuffer) Read

func (buff *SimpleBuffer) Read(b []byte) (n int, err error)

Read data, get the data, and update the read offset. @param b, the dest buffer. @return int, the length of data has read @return error, error

func (*SimpleBuffer) SimulateRead

func (buff *SimpleBuffer) SimulateRead(b []byte) (n int, err error)

Simulate reading data, only get the data, the read offset is not update. @param b, the dest buffer. @return int, the length of data has read @return error, error

func (*SimpleBuffer) Skip

func (buff *SimpleBuffer) Skip(skipLen uint32)

Skip the data. @param skipLen, the length to skip.

func (*SimpleBuffer) UpdateWriteOffset

func (buff *SimpleBuffer) UpdateWriteOffset(addLen uint32)

Update the write offset. @param addLen, the length to add.

type SyncDispatcher

type SyncDispatcher struct {
	*BaseDispatcher
}

=====================================================

SyncDispatcher

=====================================================

func NewSyncDispatcher

func NewSyncDispatcher(msgName string) *SyncDispatcher

func (*SyncDispatcher) Notify

func (d *SyncDispatcher) Notify(params ...interface{})

type SyncLimitQueue added in v0.1.9

type SyncLimitQueue struct {
	*SyncLinkedQueue
	// contains filtered or unexported fields
}

========================

SyncLimitQueue

========================

func NewSyncLimitQueue added in v0.1.9

func NewSyncLimitQueue(maxSize uint64) *SyncLimitQueue

func (*SyncLimitQueue) Enqueue added in v0.1.9

func (q *SyncLimitQueue) Enqueue(item interface{}) error

type SyncLinkedQueue

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

========================

SyncLinkedQueue

========================

func NewSyncLinkedQueue

func NewSyncLinkedQueue() *SyncLinkedQueue

func (*SyncLinkedQueue) Dequeue

func (q *SyncLinkedQueue) Dequeue() (interface{}, error)

func (*SyncLinkedQueue) Enqueue

func (q *SyncLinkedQueue) Enqueue(item interface{}) error

func (*SyncLinkedQueue) GetSize

func (q *SyncLinkedQueue) GetSize() uint64

Jump to

Keyboard shortcuts

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