Documentation ¶
Index ¶
- Variables
- func BcdToString(bcd []byte) string
- func CopyByte(dest []byte, src byte, index int) int
- func CopyStr(dest []byte, src string, index int, len int) int
- func DiceCheck(prob float64) bool
- func Equal(tlv1, tlv2 TLV) bool
- func FormatTime(time time.Time) string
- func IntToFixStr(i int64, l int) string
- func LogHex(level logging.Level, model string, bts []byte)
- func RandNum(min, max int32) int
- func SavePid(f string) string
- func StartMonitor(port int)
- func StoBcd(w string) []byte
- func TakeBytes(c gnet.Conn, bytes int) []byte
- func ToBytes(tlv TLV) ([]byte, error)
- func ToTPUDHISlices(content []byte, pkgLen int) (rt [][]byte)
- func TrimStr(bts []byte) string
- func Ucs2Decode(ucs2 []byte) string
- func Ucs2Encode(s string) []byte
- func WriteObject(tlv TLV, w io.Writer) error
- type BcdSequence
- type CycleSequence
- type TLV
- type TlvList
- func (tl *TlvList) Add(typ uint16, value []byte)
- func (tl *TlvList) AddObject(obj TLV)
- func (tl *TlvList) Get(typ uint16) (TLV, error)
- func (tl *TlvList) GetAll(typ uint16) []TLV
- func (tl *TlvList) Length() int32
- func (tl *TlvList) Remove(typ uint16) int
- func (tl *TlvList) RemoveObject(obj TLV) int
- func (tl *TlvList) String() string
- func (tl *TlvList) Write(w io.Writer) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTLVRead is returned when there is an error reading a TLV object. ErrTLVRead = fmt.Errorf("TLV %s", "read error") // ErrTLVWrite is returned when there is an error writing a TLV object. ErrTLVWrite = fmt.Errorf("TLV %s", "write error") // ErrTypeNotFound is returned when a request for a TLV type is made and none can be found. ErrTypeNotFound = fmt.Errorf("TLV %s", "type not found") )
Functions ¶
func BcdToString ¶
func FormatTime ¶
func IntToFixStr ¶
func ToTPUDHISlices ¶
ToTPUDHISlices 拆分为长短信切片 纯ASCII内容的拆分 pkgLen = 160 含中文内容的拆分 pkgLen = 140
Types ¶
type BcdSequence ¶
BcdSequence 电信MsgId序号生成器,支持每分钟产生100万个不重复序号,超出后序号会重复 BCD 4bit编码,用4bit表示0-9的数字
func NewBcdSequence ¶
func NewBcdSequence(w string) *BcdSequence
func (*BcdSequence) NextVal ¶
func (tf *BcdSequence) NextVal() []byte
type CycleSequence ¶
CycleSequence 生成可循环使用的序号 构成为: 0 | datacenter 2 bit | worker 3 bit| sequence 26 bit 最大支持32个节点,单节点2^26以内不会重复(67,108,864)
func NewCycleSequence ¶
func NewCycleSequence(d int32, w int32) *CycleSequence
NewCycleSequence d for datacenter-id, w for worker-id
func (*CycleSequence) NextVal ¶
func (s *CycleSequence) NextVal() int32
func (*CycleSequence) String ¶
func (s *CycleSequence) String() string
type TlvList ¶
type TlvList struct {
// contains filtered or unexported fields
}
TlvList is ad double-linked list containing TLV objects.
func (*TlvList) Add ¶
Add pushes a new TLV object onto the TLVList. It builds the object from its args
func (*TlvList) Get ¶
Get checks the TLVList for any object matching the type, It returns the first one found. If the type could not be found, Get returns ErrTypeNotFound.
func (*TlvList) GetAll ¶
GetAll checks the TLVList for all objects matching the type, returning a slice containing all matching objects. If no object has the requested type, an empty slice is returned.
func (*TlvList) Remove ¶
Remove removes all objects with the requested type. It returns a count of the number of removed objects.
func (*TlvList) RemoveObject ¶
RemoveObject takes an TLV object as an argument, and removes all matching objects. It matches on not just type, but also the value contained in the object.