24 lines
361 B
Go
24 lines
361 B
Go
package id_generator
|
|
|
|
import "sync"
|
|
|
|
type WebsocketId struct {
|
|
nodeId uint64
|
|
count uint64
|
|
mu sync.Mutex
|
|
}
|
|
|
|
func (wid *WebsocketId) Get() uint64 {
|
|
wid.mu.Lock()
|
|
defer wid.mu.Unlock()
|
|
wid.count++
|
|
return (wid.count << 8) | wid.nodeId
|
|
}
|
|
|
|
func NewWebsocketId(NodeId uint8) *WebsocketId {
|
|
return &WebsocketId{
|
|
nodeId: uint64(NodeId),
|
|
count: 0,
|
|
}
|
|
}
|