// Code generated by "enumer -type=Protocol -linecomment -text"; DO NOT EDIT. package nethelpers import ( "fmt" ) const ( _ProtocolName_0 = "icmp" _ProtocolName_1 = "tcp" _ProtocolName_2 = "udp" _ProtocolName_3 = "icmpv6" ) var ( _ProtocolIndex_0 = [...]uint8{0, 4} _ProtocolIndex_1 = [...]uint8{0, 3} _ProtocolIndex_2 = [...]uint8{0, 3} _ProtocolIndex_3 = [...]uint8{0, 6} ) func (i Protocol) String() string { switch { case i == 1: return _ProtocolName_0 case i == 6: return _ProtocolName_1 case i == 17: return _ProtocolName_2 case i == 58: return _ProtocolName_3 default: return fmt.Sprintf("Protocol(%d)", i) } } var _ProtocolValues = []Protocol{1, 6, 17, 58} var _ProtocolNameToValueMap = map[string]Protocol{ _ProtocolName_0[0:4]: 1, _ProtocolName_1[0:3]: 6, _ProtocolName_2[0:3]: 17, _ProtocolName_3[0:6]: 58, } // ProtocolString retrieves an enum value from the enum constants string name. // Throws an error if the param is not part of the enum. func ProtocolString(s string) (Protocol, error) { if val, ok := _ProtocolNameToValueMap[s]; ok { return val, nil } return 0, fmt.Errorf("%s does not belong to Protocol values", s) } // ProtocolValues returns all values of the enum func ProtocolValues() []Protocol { return _ProtocolValues } // IsAProtocol returns "true" if the value is listed in the enum definition. "false" otherwise func (i Protocol) IsAProtocol() bool { for _, v := range _ProtocolValues { if i == v { return true } } return false } // MarshalText implements the encoding.TextMarshaler interface for Protocol func (i Protocol) MarshalText() ([]byte, error) { return []byte(i.String()), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface for Protocol func (i *Protocol) UnmarshalText(text []byte) error { var err error *i, err = ProtocolString(string(text)) return err }