util

package
v0.0.0-...-d224df5 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIOEOF used for io.EOF.
	ErrIOEOF = io.EOF
)

Functions

func BytesToString

func BytesToString(b []byte) (s string)

BytesToString casts slice to string without copy

func CRC32

func CRC32(str string) uint32

func CalcPassword

func CalcPassword(scramble, sha1pwd []byte) []byte

CalcPassword is the algorithm convert hashed password to auth string. See https://dev.mysql.com/doc/internals/en/secure-password-authentication.html SHA1( password ) XOR SHA1( "20-bytes random data from server" <concat> SHA1( SHA1( password ) ) )

func DecodePassword

func DecodePassword(pwd string) ([]byte, error)

DecodePassword converts hex string password to byte array.

func EncodePassword

func EncodePassword(pwd string) string

EncodePassword converts plaintext password to hashed hex string.

func MD5

func MD5(str string) string

生成md5

func RunWithRetry

func RunWithRetry(retryCnt int, backoff uint64, f func() (bool, error)) (err error)

RunWithRetry will run the f with backoff and retry. retryCnt: Max retry count backoff: When run f failed, it will sleep backoff * triedCount time.Millisecond. Function f should have two return value. The first one is an bool which indicate if the err if retryable. The second is if the f meet any error.

func SHA1

func SHA1(str string) string

生成sha1

func Sha1Hash

func Sha1Hash(bs []byte) []byte

Sha1Hash is an util function to calculate sha1 hash.

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes casts string to slice without copy

func ToJSONString

func ToJSONString(v interface{}, escapeHTML bool, prefix, indent string) (string, error)

ToJSONString format v to the JSON encoding, return a string.

Types

type Buffer

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

Buffer represents the buffer_pool tuple.

func NewBuffer

func NewBuffer(cap int) *Buffer

NewBuffer creates a new buffer_pool.

func ReadBuffer

func ReadBuffer(b []byte) *Buffer

ReadBuffer used to read buffer_pool from datas.

func (*Buffer) Datas

func (b *Buffer) Datas() []byte

Datas returns the datas of the buffer_pool.

func (*Buffer) Length

func (b *Buffer) Length() int

Length returns the last position of the buffer_pool.

func (*Buffer) ReadBytes

func (b *Buffer) ReadBytes(n int) (v []byte, err error)

ReadBytes used to read bytes.

func (*Buffer) ReadBytesEOF

func (b *Buffer) ReadBytesEOF() (v []byte, err error)

ReadBytesEOF reads until the first EOF in the buffer_pool returning a byte slice containing the data up to and not including the EOF

func (*Buffer) ReadBytesNUL

func (b *Buffer) ReadBytesNUL() (v []byte, err error)

ReadBytesNUL reads until the first NUL in the buffer_pool returning a byte slice containing the data up to and not including the NUL

func (*Buffer) ReadEOF

func (b *Buffer) ReadEOF(n int) (err error)

ReadEOF used to read EOF.

func (*Buffer) ReadLenEncode

func (b *Buffer) ReadLenEncode() (v uint64, err error)

ReadLenEncode used to read variable length.

func (*Buffer) ReadLenEncodeBytes

func (b *Buffer) ReadLenEncodeBytes() (v []byte, err error)

ReadLenEncodeBytes used to read variable bytes.

func (*Buffer) ReadLenEncodeString

func (b *Buffer) ReadLenEncodeString() (s string, err error)

ReadLenEncodeString used to read variable string.

func (*Buffer) ReadString

func (b *Buffer) ReadString(n int) (s string, err error)

ReadString used to read string.

func (*Buffer) ReadStringEOF

func (b *Buffer) ReadStringEOF() (s string, err error)

ReadStringEOF reads until the first EOF in the buffer_pool returning a string containing the data up to and not including the EOF

func (*Buffer) ReadStringNUL

func (b *Buffer) ReadStringNUL() (s string, err error)

ReadStringNUL reads until the first NUL in the buffer_pool returning a string containing the data up to and not including the NUL

func (*Buffer) ReadU16

func (b *Buffer) ReadU16() (v uint16, err error)

ReadU16 used to read uint16.

func (*Buffer) ReadU24

func (b *Buffer) ReadU24() (v uint32, err error)

ReadU24 used to read uint24.

func (*Buffer) ReadU32

func (b *Buffer) ReadU32() (v uint32, err error)

ReadU32 used to read uint32.

func (*Buffer) ReadU64

func (b *Buffer) ReadU64() (v uint64, err error)

ReadU64 used to read uint64.

func (*Buffer) ReadU8

func (b *Buffer) ReadU8() (v uint8, err error)

ReadU8 used read uint8.

func (*Buffer) ReadZero

func (b *Buffer) ReadZero(n int) (err error)

ReadZero used to read zero.

func (*Buffer) Reset

func (b *Buffer) Reset(data []byte)

Reset used to reset a buffer_pool.

func (*Buffer) Seek

func (b *Buffer) Seek() int

Seek returns the seek position of the buffer_pool.

func (*Buffer) WriteBytes

func (b *Buffer) WriteBytes(bs []byte)

WriteBytes used to write bytes.

func (*Buffer) WriteEOF

func (b *Buffer) WriteEOF(n int)

WriteEOF used to write EOF.

func (*Buffer) WriteLenEncode

func (b *Buffer) WriteLenEncode(v uint64)

WriteLenEncode used to write variable length. https://dev.mysql.com/doc/internals/en/integer.html#length-encoded-integer

func (*Buffer) WriteLenEncodeBytes

func (b *Buffer) WriteLenEncodeBytes(v []byte)

WriteLenEncodeBytes used to write variable bytes.

func (*Buffer) WriteLenEncodeNUL

func (b *Buffer) WriteLenEncodeNUL()

WriteLenEncodeNUL used to write NUL> 0xfb is represents a NULL in a ProtocolText::ResultsetRow

func (*Buffer) WriteLenEncodeString

func (b *Buffer) WriteLenEncodeString(s string)

WriteLenEncodeString used to write variable string.

func (*Buffer) WriteString

func (b *Buffer) WriteString(s string)

WriteString used to write string.

func (*Buffer) WriteU16

func (b *Buffer) WriteU16(v uint16)

WriteU16 used to write uint16.

func (*Buffer) WriteU24

func (b *Buffer) WriteU24(v uint32)

WriteU24 used to write uint24.

func (*Buffer) WriteU32

func (b *Buffer) WriteU32(v uint32)

WriteU32 used to write uint32.

func (*Buffer) WriteU64

func (b *Buffer) WriteU64(v uint64)

WriteU64 used to write uint64.

func (*Buffer) WriteU8

func (b *Buffer) WriteU8(v uint8)

WriteU8 used to write uint8.

func (*Buffer) WriteZero

func (b *Buffer) WriteZero(n int)

WriteZero used to write zero.

type HashTable

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

HashTable the hash table.

func NewHashTable

func NewHashTable() *HashTable

NewHashTable create hash table.

func (*HashTable) Get

func (h *HashTable) Get(key []byte) (bool, []interface{})

Get gets the values of the "key".

func (*HashTable) Next

func (h *HashTable) Next() Iterator

Next used to iterate the HashTable.

func (*HashTable) Put

func (h *HashTable) Put(key []byte, value interface{})

Put puts the key/valueImpl pairs to the HashTable.

func (*HashTable) Size

func (h *HashTable) Size() int

Size used to get the hashtable size.

type Iterator

type Iterator func() (key []byte, value []interface{}, next Iterator)

Iterator used to iterate the HashTable.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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