forked from einride/can-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendtype.go
31 lines (26 loc) · 862 Bytes
/
sendtype.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package descriptor
import "strings"
// SendType represents the send type of a message.
type SendType uint8
//go:generate stringer -type SendType -trimprefix SendType
const (
// SendTypeNone means the send type is unknown or not specified.
SendTypeNone SendType = iota
// SendTypeCyclic means the message is sent cyclically.
SendTypeCyclic
// SendTypeEvent means the message is only sent upon event or request.
SendTypeEvent
)
// UnmarshalString sets the value of *s from the provided string.
func (s *SendType) UnmarshalString(str string) error {
// TODO: Decide on conventions and make this more strict
switch strings.ToLower(str) {
case "cyclic", "cyclicifactive", "periodic", "fixedperiodic", "enabledperiodic", "eventperiodic":
*s = SendTypeCyclic
case "event", "onevent":
*s = SendTypeEvent
default:
*s = SendTypeNone
}
return nil
}