Documentation
¶
Index ¶
- Constants
- Variables
- func Byte2Int(data []byte) int
- func Byte2Int64(data []byte) int64
- func Byte2UInt16(data []byte) uint16
- func Byte2UInt32(data []byte) uint32
- func Byte2UInt64(data []byte) uint64
- func BytesToUint64(b []byte) (uint64, error)
- func FormatFloat64ToBytes(v float64) []byte
- func FormatInt64ToBytes(v int64) []byte
- func Int2Bytes(v int) []byte
- func Int2BytesTo(v int, ret []byte)
- func Int64ToBytes(v int64) []byte
- func Int64ToBytesTo(v int64, ret []byte)
- func NewKey() string
- func NewV1Bytes() []byte
- func NewV1UUID() string
- func NewV4Bytes() []byte
- func NewV4UUID() string
- func ReadInt(r io.Reader) (int, error)
- func ReadN(r io.Reader, n int) ([]byte, error)
- func SliceToString(b []byte) (s string)
- func StrFloat64(v []byte) (float64, error)
- func StrInt64(v []byte) (int64, error)
- func StringToSlice(s string) (b []byte)
- func UInt16ToBytes(v uint16) []byte
- func UInt32ToBytes(v uint32) []byte
- func Uint16ToBytesTo(v uint16, ret []byte)
- func Uint32ToBytesTo(v uint32, ret []byte)
- func Uint64ToBytes(v uint64) []byte
- func Uint64ToBytesTo(v uint64, ret []byte)
- func UseMemPool(min, max int)
- type AddressBasedPool
- type BaseMiddleware
- func (sm *BaseMiddleware) Closed(conn IOSession)
- func (sm *BaseMiddleware) Connected(conn IOSession)
- func (sm *BaseMiddleware) PostRead(msg interface{}, conn IOSession) (bool, interface{}, error)
- func (sm *BaseMiddleware) PostWrite(msg interface{}, conn IOSession) (bool, error)
- func (sm *BaseMiddleware) PreRead(conn IOSession) (bool, interface{}, error)
- func (sm *BaseMiddleware) PreWrite(msg interface{}, conn IOSession) (bool, interface{}, error)
- func (sm *BaseMiddleware) ReadError(err error, conn IOSession) error
- func (sm *BaseMiddleware) WriteError(err error, conn IOSession)
- type ByteBuf
- func (b *ByteBuf) Capacity() int
- func (b *ByteBuf) Clear()
- func (b *ByteBuf) Expansion(n int)
- func (b *ByteBuf) GetMarkedRemind() int
- func (b *ByteBuf) GetMarkedRemindData() []byte
- func (b *ByteBuf) GetMarkerIndex() int
- func (b *ByteBuf) GetReaderIndex() int
- func (b *ByteBuf) GetWriteIndex() int
- func (b *ByteBuf) MarkIndex(index int) error
- func (b *ByteBuf) MarkN(n int) error
- func (b *ByteBuf) MarkWrite()
- func (b *ByteBuf) MarkedBytesReaded()
- func (b *ByteBuf) PeekByte(offset int) (byte, error)
- func (b *ByteBuf) PeekInt(offset int) (int, error)
- func (b *ByteBuf) PeekN(offset int, n int) ([]byte, error)
- func (b *ByteBuf) RawBuf() []byte
- func (b *ByteBuf) Read(p []byte) (n int, err error)
- func (b *ByteBuf) ReadAll() (int, []byte, error)
- func (b *ByteBuf) ReadByte() (byte, error)
- func (b *ByteBuf) ReadBytes(n int) (int, []byte, error)
- func (b *ByteBuf) ReadFrom(r io.Reader) (n int64, err error)
- func (b *ByteBuf) ReadInt() (int, error)
- func (b *ByteBuf) ReadInt64() (int64, error)
- func (b *ByteBuf) ReadMarkedBytes() (int, []byte, error)
- func (b *ByteBuf) ReadRawBytes(n int) (int, []byte, error)
- func (b *ByteBuf) ReadUInt16() (uint16, error)
- func (b *ByteBuf) ReadUInt32() (uint32, error)
- func (b *ByteBuf) ReadUInt64() (uint64, error)
- func (b *ByteBuf) Readable() int
- func (b *ByteBuf) Release()
- func (b *ByteBuf) Resume(capacity int)
- func (b *ByteBuf) SetReaderIndex(newReaderIndex int) error
- func (b *ByteBuf) SetWriterIndex(newWriterIndex int) error
- func (b *ByteBuf) Skip(n int) error
- func (b *ByteBuf) Slice(from, to int) Slice
- func (b *ByteBuf) Wrap(data []byte)
- func (b *ByteBuf) Write(p []byte) (int, error)
- func (b *ByteBuf) WriteByte(v byte) error
- func (b *ByteBuf) WriteByteBuf(from *ByteBuf) error
- func (b *ByteBuf) WriteInt(v int) (n int, err error)
- func (b *ByteBuf) WriteInt64(v int64) (n int, err error)
- func (b *ByteBuf) WriteString(v string) error
- func (b *ByteBuf) WriteUInt16(v uint16) (n int, err error)
- func (b *ByteBuf) WriteUInt32(v uint32) (n int, err error)
- func (b *ByteBuf) WriteUInt64(v uint64) (n int, err error)
- func (b *ByteBuf) WriteUint64(v uint64) (n int, err error)
- func (b *ByteBuf) Writeable() int
- func (b *ByteBuf) WrittenDataAfterMark() Slice
- type ClientOption
- func WithClientConnectTimeout(timeout time.Duration) ClientOption
- func WithClientDecoder(decoder Decoder) ClientOption
- func WithClientEncoder(encoder Encoder) ClientOption
- func WithClientMiddleware(middlewares ...Middleware) ClientOption
- func WithClientReadBufSize(readBufSize int) ClientOption
- func WithClientWriteBufSize(writeBufSize int) ClientOption
- func WithClientWriteTimeoutHandler(timeout time.Duration, handler func(string, IOSession), ...) ClientOption
- type Closer
- type ConnStatusHandler
- type Decoder
- type Encoder
- type Factory
- type IDGenerator
- type IOSession
- type IOSessionPool
- type Int64IDGenerator
- type IntLengthFieldBasedDecoder
- type IntLengthFieldBasedEncoder
- type MessageReader
- type MessageWriter
- type Middleware
- type OffsetQueue
- type Option
- type Pool
- type RawDecoder
- type Server
- type ServerOption
- func WithServerDecoder(decoder Decoder) ServerOption
- func WithServerEncoder(encoder Encoder) ServerOption
- func WithServerIDGenerator(generator IDGenerator) ServerOption
- func WithServerMiddleware(middlewares ...Middleware) ServerOption
- func WithServerReadBufSize(readBufSize int) ServerOption
- func WithServerWriteBufSize(writeBufSize int) ServerOption
- type Slice
- type StringCodec
- type SyncCodec
- type SyncPool
- type Timeout
- type TimeoutWheel
- type UUID
- func And(u1 UUID, u2 UUID) UUID
- func FromBytes(input []byte) (u UUID, err error)
- func FromBytesOrNil(input []byte) UUID
- func FromString(input string) (u UUID, err error)
- func FromStringOrNil(input string) UUID
- func NewV1() UUID
- func NewV2(domain byte) UUID
- func NewV3(ns UUID, name string) UUID
- func NewV4() UUID
- func NewV5(ns UUID, name string) UUID
- func Or(u1 UUID, u2 UUID) UUID
- func (u UUID) Bytes() []byte
- func (u UUID) MarshalBinary() (data []byte, err error)
- func (u UUID) MarshalText() (text []byte, err error)
- func (u *UUID) Scan(src interface{}) error
- func (u *UUID) SetVariant()
- func (u *UUID) SetVersion(v byte)
- func (u UUID) String() string
- func (u *UUID) UnmarshalBinary(data []byte) (err error)
- func (u *UUID) UnmarshalText(text []byte) (err error)
- func (u UUID) Value() (driver.Value, error)
- func (u UUID) Variant() uint
- func (u UUID) Version() uint
- type UUIDV4IdGenerator
Constants ¶
const ( // FieldLength field length bytes FieldLength = 4 // DefaultMaxBodySize max default body size, 10M DefaultMaxBodySize = 1024 * 1024 * 10 )
const ( // DefaultSessionBucketSize default bucket size of session map DefaultSessionBucketSize = 64 // DefaultReadBuf read buf size DefaultReadBuf = 256 // DefaultWriteBuf write buf size DefaultWriteBuf = 256 )
const ( // KB kb KB = 1024 // MB mb MB = 1024 * 1024 )
const ( VariantNCS = iota VariantRFC4122 VariantMicrosoft VariantFuture )
UUID layout variants.
const ( DomainPerson = iota DomainGroup DomainOrg )
UUID DCE domains.
Variables ¶
var ( // ErrWrite write error ErrWrite = errors.New("goetty.net: Write failed") // ErrEmptyServers empty server error ErrEmptyServers = errors.New("goetty.Connector: Empty servers pool") // ErrIllegalState illegal state error ErrIllegalState = errors.New("goetty.Connector: Not connected") )
var (
NamespaceDNS, _ = FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
NamespaceURL, _ = FromString("6ba7b811-9dad-11d1-80b4-00c04fd430c8")
NamespaceOID, _ = FromString("6ba7b812-9dad-11d1-80b4-00c04fd430c8")
NamespaceX500, _ = FromString("6ba7b814-9dad-11d1-80b4-00c04fd430c8")
)
Predefined namespace UUIDs.
var ( // ErrClosed is the error resulting if the pool is closed via pool.Close(). ErrClosed = errors.New("pool is closed") )
var ( // ErrConnectServerSide error for can't connect to client at server side ErrConnectServerSide = errors.New("can't connect to client at server side") )
var ( // ErrSystemStopped is returned when a user tries to schedule a timeout after stopping the // timeout system. ErrSystemStopped = errors.New("Timeout System is stopped") )
var ErrTooLarge = errors.New("goetty.ByteBuf: too large")
ErrTooLarge too larger error
var Nil = UUID{}
Nil UUID is special form of UUID that is specified to have all 128 bits set to zero.
Functions ¶
func Byte2Int64 ¶
Byte2Int64 byte array to int64 value using big order
func Byte2UInt16 ¶ added in v1.2.0
Byte2UInt16 byte array to uint16 value using big order
func Byte2UInt32 ¶ added in v1.1.0
Byte2UInt32 byte array to uint32 value using big order
func Byte2UInt64 ¶ added in v1.1.0
Byte2UInt64 byte array to int64 value using big order
func BytesToUint64 ¶ added in v1.0.0
BytesToUint64 bytes -> uint64
func FormatFloat64ToBytes ¶ added in v1.0.0
FormatFloat64ToBytes float64 -> string
func FormatInt64ToBytes ¶ added in v1.0.0
FormatInt64ToBytes int64 -> string
func Int2BytesTo ¶ added in v1.0.0
Int2BytesTo int value to bytes array using big order
func Int64ToBytes ¶ added in v1.0.0
Int64ToBytes int64 value to bytes array using big order
func Int64ToBytesTo ¶ added in v1.0.0
Int64ToBytesTo int64 value to bytes array using big order
func SliceToString ¶ added in v1.0.0
SliceToString slice to string with out data copy
func StrFloat64 ¶ added in v1.0.0
StrFloat64 str -> float64
func StringToSlice ¶ added in v1.0.0
StringToSlice string to slice with out data copy
func UInt16ToBytes ¶ added in v1.2.0
UInt16ToBytes uint16 value to bytes array using big order
func UInt32ToBytes ¶ added in v1.2.0
UInt32ToBytes uint32 value to bytes array using big order
func Uint16ToBytesTo ¶ added in v1.2.0
Uint16ToBytesTo uint16 value to bytes array using big order
func Uint32ToBytesTo ¶ added in v1.2.0
Uint32ToBytesTo uint32 value to bytes array using big order
func Uint64ToBytes ¶ added in v1.0.0
Uint64ToBytes uint64 -> bytes
func Uint64ToBytesTo ¶ added in v1.1.0
Uint64ToBytesTo uint64 value to bytes array using big order
Types ¶
type AddressBasedPool ¶ added in v1.0.0
AddressBasedPool is a address based conn pool. Only one conn per address in the pool.
func NewAddressBasedPool ¶ added in v1.0.0
func NewAddressBasedPool(factory func(string) IOSession, handler ConnStatusHandler) *AddressBasedPool
NewAddressBasedPool returns a AddressBasedPool with a factory fun
func (*AddressBasedPool) ForEach ¶ added in v1.2.0
func (pool *AddressBasedPool) ForEach(visitor func(addr string, conn IOSession))
ForEach do foreach session
func (*AddressBasedPool) GetConn ¶ added in v1.0.0
func (pool *AddressBasedPool) GetConn(addr string) (IOSession, error)
GetConn returns a IOSession that connected to the address Every address has only one connection in the pool
func (*AddressBasedPool) RemoveConn ¶ added in v1.0.0
func (pool *AddressBasedPool) RemoveConn(addr string)
RemoveConn close the conn, and remove from the pool
func (*AddressBasedPool) RemoveConnIfMatches ¶ added in v1.1.0
func (pool *AddressBasedPool) RemoveConnIfMatches(addr string, target IOSession) bool
RemoveConnIfMatches close the conn, and remove from the pool if the conn in the pool is match the given
type BaseMiddleware ¶ added in v1.1.0
type BaseMiddleware struct { }
BaseMiddleware defined default reutrn value
func (*BaseMiddleware) Closed ¶ added in v1.1.0
func (sm *BaseMiddleware) Closed(conn IOSession)
Closed default option
func (*BaseMiddleware) Connected ¶ added in v1.1.0
func (sm *BaseMiddleware) Connected(conn IOSession)
Connected default option
func (*BaseMiddleware) PostRead ¶ added in v1.1.0
func (sm *BaseMiddleware) PostRead(msg interface{}, conn IOSession) (bool, interface{}, error)
PostRead default reutrn value
func (*BaseMiddleware) PostWrite ¶ added in v1.1.0
func (sm *BaseMiddleware) PostWrite(msg interface{}, conn IOSession) (bool, error)
PostWrite default reutrn value
func (*BaseMiddleware) PreRead ¶ added in v1.1.0
func (sm *BaseMiddleware) PreRead(conn IOSession) (bool, interface{}, error)
PreRead default reutrn value
func (*BaseMiddleware) PreWrite ¶ added in v1.1.0
func (sm *BaseMiddleware) PreWrite(msg interface{}, conn IOSession) (bool, interface{}, error)
PreWrite default reutrn value
func (*BaseMiddleware) ReadError ¶ added in v1.1.0
func (sm *BaseMiddleware) ReadError(err error, conn IOSession) error
ReadError conn read err
func (*BaseMiddleware) WriteError ¶ added in v1.1.0
func (sm *BaseMiddleware) WriteError(err error, conn IOSession)
WriteError conn write err
type ByteBuf ¶
type ByteBuf struct {
// contains filtered or unexported fields
}
ByteBuf a buf with byte arrays
| discardable bytes | readable bytes | writeable bytes | | | | | | | | | 0 <= readerIndex <= writerIndex <= capacity
func NewByteBufPool ¶ added in v1.0.0
NewByteBufPool create a new bytebuf using a mem pool
func (*ByteBuf) GetMarkedRemind ¶ added in v1.0.0
GetMarkedRemind returns size in [readerIndex, markedIndex)
func (*ByteBuf) GetMarkedRemindData ¶ added in v1.0.0
GetMarkedRemindData returns data in [readerIndex, markedIndex)
func (*ByteBuf) GetMarkerIndex ¶ added in v1.0.0
GetMarkerIndex returns markerIndex
func (*ByteBuf) GetReaderIndex ¶
GetReaderIndex get the read index
func (*ByteBuf) GetWriteIndex ¶
GetWriteIndex get the write index
func (*ByteBuf) MarkWrite ¶ added in v1.4.0
func (b *ByteBuf) MarkWrite()
MarkWrite mark current write index
func (*ByteBuf) MarkedBytesReaded ¶ added in v1.0.0
func (b *ByteBuf) MarkedBytesReaded()
MarkedBytesReaded reset reader index
func (*ByteBuf) PeekByte ¶ added in v1.0.0
PeekByte get byte value from buf based on currently read index, after read, read index not modifed
func (*ByteBuf) PeekInt ¶
PeekInt get int value from buf based on currently read index, after read, read index not modifed
func (*ByteBuf) PeekN ¶
PeekN get bytes from buf based on currently read index, after read, read index not modifed
func (*ByteBuf) ReadAll ¶
ReadAll read all data from buf It's will copy the data to a new byte arrary return readedBytesCount, byte array, error
func (*ByteBuf) ReadBytes ¶
ReadBytes read bytes from buf It's will copy the data to a new byte arrary return readedBytesCount, byte array, error
func (*ByteBuf) ReadFrom ¶
ReadFrom reads data from r until EOF and appends it to the buffer, growing the buffer as needed. The return value n is the number of bytes read. Any error except io.EOF encountered during the read is also returned. If the buffer becomes too large, ReadFrom will panic with ErrTooLarge.
func (*ByteBuf) ReadMarkedBytes ¶
ReadMarkedBytes read data from buf in the range [readerIndex, markedIndex)
func (*ByteBuf) ReadRawBytes ¶ added in v1.0.0
ReadRawBytes read bytes from buf without mem copy Note. If used complete, you must call b.Skip(n) to reset reader index
func (*ByteBuf) ReadUInt16 ¶ added in v1.2.0
ReadUInt16 get uint16 value from buf
func (*ByteBuf) ReadUInt32 ¶ added in v1.1.0
ReadUInt32 get uint32 value from buf
func (*ByteBuf) ReadUInt64 ¶ added in v1.1.0
ReadUInt64 get uint64 value from buf
func (*ByteBuf) SetReaderIndex ¶
SetReaderIndex set the read index
func (*ByteBuf) SetWriterIndex ¶
SetWriterIndex set the write index
func (*ByteBuf) Write ¶
Write appends the contents of p to the buffer, growing the buffer as needed.
func (*ByteBuf) WriteByteBuf ¶ added in v1.1.0
WriteByteBuf write all readable data to this buf
func (*ByteBuf) WriteInt ¶
WriteInt write int value to buf using big order return write bytes count, error
func (*ByteBuf) WriteInt64 ¶ added in v1.0.0
WriteInt64 write int64 value to buf using big order return write bytes count, error
func (*ByteBuf) WriteString ¶ added in v1.1.0
WriteString write a string value to buf
func (*ByteBuf) WriteUInt16 ¶ added in v1.2.0
WriteUInt16 write uint16 value to buf using big order return write bytes count, error
func (*ByteBuf) WriteUInt32 ¶ added in v1.2.0
WriteUInt32 write uint32 value to buf using big order return write bytes count, error
func (*ByteBuf) WriteUInt64 ¶ added in v1.2.0
WriteUInt64 write uint64 value to buf using big order return write bytes count, error
func (*ByteBuf) WriteUint64 ¶ added in v1.1.0
WriteUint64 write uint64 value to buf using big order return write bytes count, error
func (*ByteBuf) WrittenDataAfterMark ¶ added in v1.4.0
WrittenDataAfterMark returns the data referance after mark write
type ClientOption ¶ added in v1.1.0
type ClientOption func(*clientOptions)
ClientOption option of client side
func WithClientConnectTimeout ¶ added in v1.1.0
func WithClientConnectTimeout(timeout time.Duration) ClientOption
WithClientConnectTimeout option of timeout to connect to server
func WithClientDecoder ¶ added in v1.1.0
func WithClientDecoder(decoder Decoder) ClientOption
WithClientDecoder option of client's decoder
func WithClientEncoder ¶ added in v1.1.0
func WithClientEncoder(encoder Encoder) ClientOption
WithClientEncoder option of client's encoder
func WithClientMiddleware ¶ added in v1.1.0
func WithClientMiddleware(middlewares ...Middleware) ClientOption
WithClientMiddleware option of handle write timeout
func WithClientReadBufSize ¶ added in v1.1.0
func WithClientReadBufSize(readBufSize int) ClientOption
WithClientReadBufSize option of client's read buf size
func WithClientWriteBufSize ¶ added in v1.1.0
func WithClientWriteBufSize(writeBufSize int) ClientOption
WithClientWriteBufSize option of client's write buf size
func WithClientWriteTimeoutHandler ¶ added in v1.1.0
func WithClientWriteTimeoutHandler(timeout time.Duration, handler func(string, IOSession), timeWheel *TimeoutWheel) ClientOption
WithClientWriteTimeoutHandler option of handle write timeout
type ConnStatusHandler ¶ added in v1.0.0
type ConnStatusHandler interface { ConnectFailed(addr string, err error) Connected(addr string, conn IOSession) }
ConnStatusHandler handler for conn status
type Decoder ¶
Decoder decoder interface
func NewEmptyDecoder ¶ added in v1.1.0
func NewEmptyDecoder() Decoder
NewEmptyDecoder returns a empty decoder
func NewIntLengthFieldBasedDecoder ¶
NewIntLengthFieldBasedDecoder create a IntLengthFieldBasedDecoder
func NewIntLengthFieldBasedDecoderSize ¶
func NewIntLengthFieldBasedDecoderSize(base Decoder, lengthFieldOffset, lengthAdjustment, initialBytesToStrip, maxBodySize int) Decoder
NewIntLengthFieldBasedDecoderSize create a IntLengthFieldBasedDecoder initialBytesToStrip + lengthFieldOffset + 4(length) lengthAdjustment, some case as below: 1. 0 : base decoder received: body 2. -4: base decoder received: 4(length) + body 3. -(4 + lengthFieldOffset): base decoder received: lengthFieldOffset + 4(length) + body 4. -(4 + lengthFieldOffset + initialBytesToStrip): base decoder received: initialBytesToStrip + lengthFieldOffset + 4(length)
type Encoder ¶
Encoder encode interface
func NewEmptyEncoder ¶ added in v1.0.0
func NewEmptyEncoder() Encoder
NewEmptyEncoder returns a empty encoder
func NewIntLengthFieldBasedEncoder ¶ added in v1.1.0
NewIntLengthFieldBasedEncoder returns a encoder with base
func NewRawEncoder ¶ added in v1.3.3
func NewRawEncoder() Encoder
NewRawEncoder returns a encoder to encode raw byte array
type IDGenerator ¶ added in v1.0.0
type IDGenerator interface {
NewID() interface{}
}
IDGenerator ID Generator interface
func NewInt64IDGenerator ¶ added in v1.0.0
func NewInt64IDGenerator() IDGenerator
NewInt64IDGenerator create a uuid v4 generator
func NewUUIDV4IdGenerator ¶
func NewUUIDV4IdGenerator() IDGenerator
NewUUIDV4IdGenerator create a uuid v4 generator
type IOSession ¶
type IOSession interface { ID() interface{} Hash() int Close() error IsConnected() bool Connect() (bool, error) Read() (interface{}, error) ReadTimeout(timeout time.Duration) (interface{}, error) Write(msg interface{}) error WriteAndFlush(msg interface{}) error Flush() error InBuf() *ByteBuf OutBuf() *ByteBuf SetAttr(key string, value interface{}) GetAttr(key string) interface{} RemoteAddr() string RemoteIP() string }
IOSession session
func NewConnector ¶
func NewConnector(svrAddr string, opts ...ClientOption) IOSession
NewConnector create a new connector with opts
type IOSessionPool ¶ added in v1.0.0
type IOSessionPool interface { // Get returns a new connection from the pool. Closing the connections puts // it back to the Pool. Closing it when the pool is destroyed or full will // be counted as an error. Get() (IOSession, error) // Put puts the connection back to the pool. If the pool is full or closed, // conn is simply closed. A nil conn will be rejected. Put(IOSession) error // Close closes the pool and all its connections. After Close() the pool is // no longer usable. Close() // Len returns the current number of connections of the pool. Len() int }
IOSessionPool interface describes a pool implementation. A pool should have maximum capacity. An ideal pool is threadsafe and easy to use.
func NewIOSessionPool ¶ added in v1.0.0
func NewIOSessionPool(initialCap, maxCap int, factory Factory) (IOSessionPool, error)
NewIOSessionPool returns a new pool based on buffered channels with an initial capacity and maximum capacity. Factory is used when initial capacity is greater than zero to fill the pool. A zero initialCap doesn't fill the Pool until a new Get() is called. During a Get(), If there is no new connection available in the pool, a new connection will be created via the Factory() method.
type Int64IDGenerator ¶ added in v1.0.0
type Int64IDGenerator struct {
// contains filtered or unexported fields
}
Int64IDGenerator int64 id Generator
func (*Int64IDGenerator) NewID ¶ added in v1.0.0
func (g *Int64IDGenerator) NewID() interface{}
NewID return a id
type IntLengthFieldBasedDecoder ¶
type IntLengthFieldBasedDecoder struct {
// contains filtered or unexported fields
}
IntLengthFieldBasedDecoder decoder based on length filed + data
type IntLengthFieldBasedEncoder ¶ added in v1.1.0
type IntLengthFieldBasedEncoder struct {
// contains filtered or unexported fields
}
IntLengthFieldBasedEncoder encoder based on length filed + data
func (*IntLengthFieldBasedEncoder) Encode ¶ added in v1.1.0
func (encoder *IntLengthFieldBasedEncoder) Encode(data interface{}, out *ByteBuf) error
Encode encode
type MessageReader ¶ added in v1.0.0
type MessageReader interface { Read() (interface{}, error) ReadTimeout(timeout time.Duration) (interface{}, error) }
MessageReader is a message reader
type MessageWriter ¶ added in v1.0.0
type MessageWriter interface {
Write(msg interface{}) error
}
MessageWriter is a message writer
type Middleware ¶ added in v1.1.0
type Middleware interface { PreRead(conn IOSession) (bool, interface{}, error) PostRead(msg interface{}, conn IOSession) (bool, interface{}, error) PreWrite(msg interface{}, conn IOSession) (bool, interface{}, error) PostWrite(msg interface{}, conn IOSession) (bool, error) Closed(conn IOSession) Connected(conn IOSession) WriteError(err error, conn IOSession) ReadError(err error, conn IOSession) error }
Middleware goetty middleware
func NewSyncProtocolClientMiddleware ¶ added in v1.1.0
func NewSyncProtocolClientMiddleware(bizDecoder Decoder, bizEncoder Encoder, writer func(IOSession, interface{}) error, maxReadTimeouts int) Middleware
NewSyncProtocolClientMiddleware return a middleware to process sync protocol
func NewSyncProtocolServerMiddleware ¶ added in v1.1.0
func NewSyncProtocolServerMiddleware(bizDecoder Decoder, bizEncoder Encoder, writer func(IOSession, interface{}) error) Middleware
NewSyncProtocolServerMiddleware return a middleware to process sync protocol
type OffsetQueue ¶ added in v1.1.0
OffsetQueue is a queue for sync.
func (*OffsetQueue) Add ¶ added in v1.1.0
func (q *OffsetQueue) Add(item interface{}) uint64
Add add a item to the queue
func (*OffsetQueue) Get ¶ added in v1.1.0
func (q *OffsetQueue) Get(offset uint64) ([]interface{}, uint64)
Get returns all the items after the offset, and remove all items before this offset
func (*OffsetQueue) GetMaxOffset ¶ added in v1.1.0
func (q *OffsetQueue) GetMaxOffset() uint64
GetMaxOffset returns the max offset in the queue
type Option ¶ added in v1.0.0
type Option func(*opts)
Option is a configuration option to NewTimeoutWheel
func WithBucketsExponent ¶ added in v1.0.0
WithBucketsExponent sets the number of buckets in the hash table.
func WithLocksExponent ¶ added in v1.0.0
WithLocksExponent sets the number locks in the lockpool used to lock the time buckets. If the number is greater than the number of buckets, the number of buckets will be used instead.
func WithTickInterval ¶ added in v1.0.0
WithTickInterval sets the frequency of ticks.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server tcp server
func (*Server) GetSession ¶
GetSession get session by id
func (*Server) Start ¶ added in v1.0.0
Start start the server, this method will block until occur a error
type ServerOption ¶ added in v1.1.0
type ServerOption func(*serverOptions)
ServerOption option of server side
func WithServerDecoder ¶ added in v1.1.0
func WithServerDecoder(decoder Decoder) ServerOption
WithServerDecoder option of server's decoder
func WithServerEncoder ¶ added in v1.1.0
func WithServerEncoder(encoder Encoder) ServerOption
WithServerEncoder option of server's encoder
func WithServerIDGenerator ¶ added in v1.1.0
func WithServerIDGenerator(generator IDGenerator) ServerOption
WithServerIDGenerator option of server's id generator
func WithServerMiddleware ¶ added in v1.1.0
func WithServerMiddleware(middlewares ...Middleware) ServerOption
WithServerMiddleware option of handle write timeout
func WithServerReadBufSize ¶ added in v1.1.0
func WithServerReadBufSize(readBufSize int) ServerOption
WithServerReadBufSize option of server's read buf size
func WithServerWriteBufSize ¶ added in v1.1.0
func WithServerWriteBufSize(writeBufSize int) ServerOption
WithServerWriteBufSize option of server's write buf size
type Slice ¶ added in v1.6.0
type Slice struct {
// contains filtered or unexported fields
}
Slice the slice of byte buf
type StringCodec ¶ added in v1.1.0
type StringCodec struct{}
StringCodec a simple string encoder and decoder
func (*StringCodec) Decode ¶ added in v1.1.0
func (codec *StringCodec) Decode(in *ByteBuf) (bool, interface{}, error)
Decode decode
func (*StringCodec) Encode ¶ added in v1.1.0
func (codec *StringCodec) Encode(data interface{}, out *ByteBuf) error
Encode encode
type SyncCodec ¶ added in v1.1.0
type SyncCodec struct{}
SyncCodec sync protocol dercoder and encoder
type SyncPool ¶ added in v1.0.0
type SyncPool struct {
// contains filtered or unexported fields
}
SyncPool is a sync.Pool base slab allocation memory pool
func NewSyncPool ¶ added in v1.0.0
NewSyncPool create a sync.Pool base slab allocation memory pool. minSize is the smallest chunk size. maxSize is the lagest chunk size. factor is used to control growth of chunk size.
type Timeout ¶ added in v1.0.0
type Timeout struct {
// contains filtered or unexported fields
}
Timeout represents a single timeout function pending expiration.
type TimeoutWheel ¶ added in v1.0.0
type TimeoutWheel struct {
// contains filtered or unexported fields
}
TimeoutWheel is a bucketed collection of Timeouts that have a deadline in the future. (current tick granularity is 1ms).
func NewTimeoutWheel ¶ added in v1.0.0
func NewTimeoutWheel(options ...Option) *TimeoutWheel
NewTimeoutWheel creates and starts a new TimeoutWheel collection.
func (*TimeoutWheel) Schedule ¶ added in v1.0.0
func (t *TimeoutWheel) Schedule( d time.Duration, expireCb func(interface{}), arg interface{}, ) (Timeout, error)
Schedule adds a new function to be called after some duration of time has elapsed. The returned Timeout can be used to cancel calling the function. If the duration falls between two ticks, the latter tick is used.
func (*TimeoutWheel) Start ¶ added in v1.0.0
func (t *TimeoutWheel) Start()
Start starts a stopped timeout wheel. Subsequent calls to Start panic.
func (*TimeoutWheel) Stop ¶ added in v1.0.0
func (t *TimeoutWheel) Stop()
Stop stops tick processing, and deletes any remaining timeouts.
type UUID ¶ added in v1.0.0
type UUID [16]byte
UUID representation compliant with specification described in RFC 4122.
func FromBytes ¶ added in v1.0.0
FromBytes returns UUID converted from raw byte slice input. It will return error if the slice isn't 16 bytes long.
func FromBytesOrNil ¶ added in v1.0.0
FromBytesOrNil returns UUID converted from raw byte slice input. Same behavior as FromBytes, but returns a Nil UUID on error.
func FromString ¶ added in v1.0.0
FromString returns UUID parsed from string input. Input is expected in a form accepted by UnmarshalText.
func FromStringOrNil ¶ added in v1.0.0
FromStringOrNil returns UUID parsed from string input. Same behavior as FromString, but returns a Nil UUID on error.
func NewV1 ¶ added in v1.0.0
func NewV1() UUID
NewV1 returns UUID based on current timestamp and MAC address.
func (UUID) MarshalBinary ¶ added in v1.0.0
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (UUID) MarshalText ¶ added in v1.0.0
MarshalText implements the encoding.TextMarshaler interface. The encoding is the same as returned by String.
func (*UUID) Scan ¶ added in v1.0.0
Scan implements the sql.Scanner interface. A 16-byte slice is handled by UnmarshalBinary, while a longer byte slice or a string is handled by UnmarshalText.
func (*UUID) SetVariant ¶ added in v1.0.0
func (u *UUID) SetVariant()
SetVariant sets variant bits as described in RFC 4122.
func (*UUID) SetVersion ¶ added in v1.0.0
SetVersion sets version bits.
func (UUID) String ¶ added in v1.0.0
Returns canonical string representation of UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
func (*UUID) UnmarshalBinary ¶ added in v1.0.0
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface. It will return error if the slice isn't 16 bytes long.
func (*UUID) UnmarshalText ¶ added in v1.0.0
UnmarshalText implements the encoding.TextUnmarshaler interface. Following formats are supported: "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}", "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8"
type UUIDV4IdGenerator ¶
type UUIDV4IdGenerator struct { }
UUIDV4IdGenerator uuid v4 generator
func (*UUIDV4IdGenerator) NewID ¶ added in v1.0.0
func (g *UUIDV4IdGenerator) NewID() interface{}
NewID return a id