Documentation ¶
Overview ¶
Package util includes common tools for various Bisquitt packages.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ClientState ¶
type ClientState uint32
const ( StateDisconnected ClientState = iota StateActive StateAsleep StateAwake )
Client state constants. See MQTT-SN spec v. 1.2, chapter 6.14, p. 25
func (*ClientState) Get ¶
func (s *ClientState) Get() ClientState
Get atomically gets ClientState's value.
func (*ClientState) Set ¶
func (s *ClientState) Set(new ClientState) ClientState
Set atomically sets ClientState's value and returns old value.
func (ClientState) String ¶
func (s ClientState) String() string
String atomically get ClientState's value and converts it to human-readable string.
type ConnWithContext ¶
type ConnWithContext struct {
// contains filtered or unexported fields
}
ConnWithContext is a net.Conn wrapper which implements io.ReadWriteCloser interface with Read and Write methods cancellable using context.Context.
func NewConnWithContext ¶
NewConnWithContext creates a new ConnWithContext instance.
The timeout parameter sets a "time granularity". Since Go does not support immediate cancellation of Read nor Write call, these calls will be canceled in at most "timeout" time after ctx cancellation. Lower timeout causes slightly higher overhead.
func (*ConnWithContext) Close ¶
func (c *ConnWithContext) Close() error
type DebugLogger ¶
type DebugLogger struct {
// contains filtered or unexported fields
}
DebugLogger is a Logger implementation which writes time, severity, tags and message to the console. Time is written in microseconds modulo 10^8.
func (DebugLogger) Debug ¶
func (l DebugLogger) Debug(format string, a ...interface{})
func (DebugLogger) Error ¶
func (l DebugLogger) Error(format string, a ...interface{})
func (DebugLogger) Info ¶
func (l DebugLogger) Info(format string, a ...interface{})
func (DebugLogger) Sync ¶
func (l DebugLogger) Sync()
func (DebugLogger) WithTag ¶
func (l DebugLogger) WithTag(tag string) Logger
type IDSequence ¶
type IDSequence struct {
// contains filtered or unexported fields
}
IDSequence generates successive uint16 IDs from (minID, maxID) range. When maxID is reached, the counter wraps to minID on the following Next() call and the overflow is signalized.
func NewIDSequence ¶
func NewIDSequence(minID, maxID uint16) *IDSequence
NewIDSequence creates a new IDSequence.
Both minID and maxID are inclusive.
func (*IDSequence) Next ¶
func (c *IDSequence) Next() (id uint16, overflow bool)
Next returns a new ID. If (maxID, false) is returned, the following call will return (minID, true).
Example ¶
s := NewIDSequence(1, 3) for i := 0; i < 8; i++ { id, overflow := s.Next() fmt.Printf("id=%d, overflow=%t\n", id, overflow) }
Output: id=1, overflow=false id=2, overflow=false id=3, overflow=false id=1, overflow=true id=2, overflow=false id=3, overflow=false id=1, overflow=true id=2, overflow=false
type Logger ¶
type Logger interface { // Debug logs a message with a "debug" severity. Debug(format string, a ...interface{}) // Info logs a message with an "info" severity. Info(format string, a ...interface{}) // Error logs a message with an "error" severity. Error(format string, a ...interface{}) // WithTag returns a copy of the Logger with "tag" added to the existing // tags. WithTag(tag string) Logger // Sync writes pending messages out (flushes message buffers, if any). Sync() }
Logger is a strings-tagged, severity-aware logger interface.
func NewDebugLogger ¶
func NewProductionLogger ¶
type NoOpLogger ¶
type NoOpLogger struct{}
NoOpLogger is a Logger implementation which does not log anything.
func (NoOpLogger) Debug ¶
func (l NoOpLogger) Debug(format string, a ...interface{})
func (NoOpLogger) Error ¶
func (l NoOpLogger) Error(format string, a ...interface{})
func (NoOpLogger) Info ¶
func (l NoOpLogger) Info(format string, a ...interface{})
func (NoOpLogger) Sync ¶
func (l NoOpLogger) Sync()
func (NoOpLogger) WithTag ¶
func (l NoOpLogger) WithTag(tag string) Logger
type ProductionLogger ¶
type ProductionLogger struct {
// contains filtered or unexported fields
}
ProductionLogger is a Logger implementation which writes severity, tags and message to the console. Debug severity messages are ignored.
func (ProductionLogger) Debug ¶
func (l ProductionLogger) Debug(format string, a ...interface{})
func (ProductionLogger) Error ¶
func (l ProductionLogger) Error(format string, a ...interface{})
func (ProductionLogger) Info ¶
func (l ProductionLogger) Info(format string, a ...interface{})
func (ProductionLogger) Sync ¶
func (l ProductionLogger) Sync()
func (ProductionLogger) WithTag ¶
func (l ProductionLogger) WithTag(tag string) Logger
type SyslogLogger ¶
type SyslogLogger struct {
// contains filtered or unexported fields
}
SyslogLogger writes log messages to the syslog using /dev/log socket. Debug severity messages are written optionally.
func (*SyslogLogger) Debug ¶
func (l *SyslogLogger) Debug(format string, a ...interface{})
func (*SyslogLogger) Error ¶
func (l *SyslogLogger) Error(format string, a ...interface{})
func (*SyslogLogger) Info ¶
func (l *SyslogLogger) Info(format string, a ...interface{})
func (*SyslogLogger) Sync ¶
func (l *SyslogLogger) Sync()
func (*SyslogLogger) WithTag ¶
func (l *SyslogLogger) WithTag(tag string) Logger