Documentation
¶
Index ¶
- Constants
- Variables
- func SendMsg(msg message.Messager, writer io.Writer) error
- type Client
- type Data
- type DataTable
- func (t *DataTable) ContainsKey(key string) bool
- func (t *DataTable) ContainsTable(key string) bool
- func (t *DataTable) Delete(key string)
- func (t *DataTable) DeleteAll()
- func (t *DataTable) GetBoolean(key string, def bool) bool
- func (t *DataTable) GetBooleanArray(key string, def []bool) []bool
- func (t *DataTable) GetKeys() []string
- func (t *DataTable) GetNumber(key string, def float64) float64
- func (t *DataTable) GetNumberArray(key string, def []float64) []float64
- func (t *DataTable) GetRaw(key string, def []byte) []byte
- func (t *DataTable) GetString(key string, def string) string
- func (t *DataTable) GetStringArray(key string, def []string) []string
- func (t *DataTable) GetTable(key string) NetworkTabler
- func (t *DataTable) IsPersisted(key string) bool
- func (t *DataTable) PutBoolean(key string, val bool) bool
- func (t *DataTable) PutBooleanArray(key string, val []bool) bool
- func (t *DataTable) PutNumber(key string, val float64) bool
- func (t *DataTable) PutNumberArray(key string, val []float64) bool
- func (t *DataTable) PutRaw(key string, val []byte) bool
- func (t *DataTable) PutString(key string, val string) bool
- func (t *DataTable) PutStringArray(key string, val []string) bool
- type Entry
- type LogMessage
- type NetworkTabler
- type Server
Constants ¶
const ( //PORT is the port on which all clients and servers communicate on. PORT = 1735 //PENDING is the client status used to make sure that the handshake has been completed. PENDING = "pending" //LISTENING is used during the handshake to specify it if looking to see what the server has. LISTENING = "listening" //READY is used to state that the client has finished the handshake. READY = "ready" )
Variables ¶
var ( //ProtocolVersion is what protocol this package supports ProtocolVersion = [2]byte{0x03, 0x00} )
Functions ¶
Types ¶
type Client ¶
type Client struct {
net.Conn
Log chan LogMessage
// contains filtered or unexported fields
}
Client is a Network Table client.
func (*Client) Listen ¶
func (c *Client) Listen()
Listen for messages sent from the server. Best to start this in a go routine.
func (*Client) StartHandshake ¶
StartHandshake starts the handshake with the server.
type Data ¶
type Data interface {
PutEntry(ent *Entry) error //Creates if new, updates otherwise
GetEntries(root string) ([]string, error)
GetEntry(key string) (*Entry, error)
DeleteEntry(key string) error
DeleteAll(root string) error
IsTable(key string) bool
IsKey(key string) bool
}
Data is the interface implemented by types that can read and write Network Table at a low level.
type DataTable ¶
type DataTable struct {
// contains filtered or unexported fields
}
DataTable implements NetworkTabler based on a backend that needs to exist on create.
func NewTable ¶
NewTable creates a new Network Table that is based off of the data and root passed in. Pass in an empty string or "/" for root table.
func (*DataTable) ContainsKey ¶
ContainsKey returns true if the key exist in the table.
func (*DataTable) ContainsTable ¶
ContainsTable return true if the table exist in the table.
func (*DataTable) DeleteAll ¶
func (t *DataTable) DeleteAll()
DeleteAll deletes all keys from the table.
func (*DataTable) GetBoolean ¶
GetBoolean gets the value of key as a boolean. If the value is not of type boolean it returns the default value passed in.
func (*DataTable) GetBooleanArray ¶
GetBooleanArray gets the value of key as a slice of booleans. If the value is not of type boolean slice it returns the default value passed in.
func (*DataTable) GetNumber ¶
GetNumber gets the value of key as a float64. If the value is not of type float64 it returns the default value passed in.
func (*DataTable) GetNumberArray ¶
GetNumberArray gets the value of key as a slice of float64s. If the value is not of type float64 slice it returns the default value passed in.
func (*DataTable) GetRaw ¶
GetRaw gets the value of key as a slice of bytes. If the value is not of type byte slice it returns the default value passed in.
func (*DataTable) GetString ¶
GetString gets the value of key as a string. If the value is not of type string it returns the default value passed in.
func (*DataTable) GetStringArray ¶
GetStringArray gets the value of key as a slice of strings. If the value is not of type string slice it returns the default value passed in.
func (*DataTable) GetTable ¶
func (t *DataTable) GetTable(key string) NetworkTabler
GetTable gets a table with the specified key. If table does not exist it creates a new one.
func (*DataTable) IsPersisted ¶
IsPersisted returns true if the key is to be persisted. Returns false if the key does not exist.
func (*DataTable) PutBoolean ¶
PutBoolean puts the boolean value in the table. If value exist it updates it. If value doesn't exist it will add it. Returns false if key exist of a different type.
func (*DataTable) PutBooleanArray ¶
PutBooleanArray puts the slice of boolean in the table. If value exist it updates it. If value doesn't exist it will add it. Returns false if key exist of a different type.
func (*DataTable) PutNumber ¶
PutNumber puts the float64 value in the table. If value exist it updates it. If value doesn't exist it will add it. Returns false if key exist of a different type.
func (*DataTable) PutNumberArray ¶
PutNumberArray puts the slice of float64 in the table. If value exist it updates it. If value doesn't exist it will add it. Returns false if key exist of a different type.
func (*DataTable) PutRaw ¶
PutRaw puts the taw value in the table. If value exist it updates it. If value doesn't exist it will add it. Returns false if key exist of a different type.
type LogMessage ¶
LogMessage is used to send information back to the running process about the server.
func NewErrorMessage ¶
func NewErrorMessage(err error) LogMessage
NewErrorMessage creates a new log message with the error filled out.
func NewLogMessage ¶
func NewLogMessage(msg string) LogMessage
NewLogMessage creates a log message with the message filled out.
type NetworkTabler ¶
type NetworkTabler interface {
ContainsKey(key string) bool
ContainsTable(key string) bool
Delete(key string)
DeleteAll()
IsPersisted(key string) bool
GetKeys() []string
GetTable(key string) NetworkTabler
GetBoolean(key string, def bool) bool
PutBoolean(key string, val bool) bool
GetNumber(key string, def float64) float64
PutNumber(key string, val float64) bool
GetString(key string, def string) string
PutString(key string, val string) bool
GetRaw(key string, def []byte) []byte
PutRaw(key string, val []byte) bool
GetBooleanArray(key string, def []bool) []bool
PutBooleanArray(key string, val []bool) bool
GetNumberArray(key string, def []float64) []float64
PutNumberArray(key string, val []float64) bool
GetStringArray(key string, def []string) []string
PutStringArray(key string, val []string) bool
}
NetworkTabler is the interface implemented by types that can read and write Network Table at a high level.
type Server ¶
type Server struct {
Log chan LogMessage
// contains filtered or unexported fields
}
Server is an instance of a Network Table server.
func (*Server) Listen ¶
func (s *Server) Listen()
Listen starts listening on the network for messages. Spin off a new goroutine to connect to the client. Keep the connection to the client open to allow for communication in both directions.
func (*Server) SendMsg ¶
SendMsg sends a message to each connected client that is ready. Never returns an error and does not wait for execution to finish.
func (*Server) StartPeriodicClean ¶
StartPeriodicClean cleans up instances of connections that have been closed. It cleans every d (durtaion).