Documentation ¶
Index ¶
- Variables
- func BcdToString(bcd []byte) string
- func Bytes2StringSlice(in []byte, pl int) (ret []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 GB18030ToUtf8(in string) (string, error)
- func IntToFixStr(i int64, l int) string
- func IsBigEndian() bool
- func Now() (string, uint32)
- func OctetString(s string, fixedLength int) string
- func RandNum(min, max int) int
- func StoBcd(w string) []byte
- func TimeStamp2Str(t uint32) string
- func ToBytes(tlv TLV) ([]byte, error)
- func ToTPUDHISlices(content []byte, pkgLen int) (rt [][]byte)
- func TrimOctetString(in []byte) []byte
- func TrimStr(in []byte) string
- func Ucs2ToUtf8(in []byte) (string, error)
- func Uint32HexString(i uint32) string
- func Uint64HexString(i uint64) string
- func Utf8ToGB18030(in string) (string, error)
- func Utf8ToUcs2(in string) ([]byte, error)
- 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") )
var ErrInvalidUtf8Rune = errors.New("Not Invalid Utf8 runes")
var NumTable = [16]byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}
Functions ¶
func BcdToString ¶
func Bytes2StringSlice ¶ added in v0.2.0
func FormatTime ¶ added in v0.2.0
func GB18030ToUtf8 ¶
func IntToFixStr ¶
func IsBigEndian ¶
func IsBigEndian() bool
func OctetString ¶
func TimeStamp2Str ¶
TimeStamp2Str converts a timestamp(MMDDHHMMSS) int to a string(10 bytes).
func ToTPUDHISlices ¶
ToTPUDHISlices 拆分为长短信切片 纯ASCII内容的拆分 pkgLen = 160 含中文内容的拆分 pkgLen = 140
func TrimOctetString ¶
func Ucs2ToUtf8 ¶
func Uint32HexString ¶ added in v0.2.0
func Uint64HexString ¶ added in v0.2.0
func Utf8ToGB18030 ¶
func Utf8ToUcs2 ¶
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.