talos/pkg/machinery/nethelpers/routeprotocol_enumer.go
Andrey Smirnov d02d944ec7
chore: provide umarshal from YAML methods for network resource specs
This will be required to preserve platform network configuration in a
cache across boots. Network configuration will be marshaled to YAML and
unmarshaled back.

Changes are pretty simple and most of the code is auto-generated:
replace `stringer` codegen with `enumer` which produces also methods
which convert from string back to enum values.

Added tests to verify YAML marshaling/unmarshaling.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
2022-01-10 17:00:53 +03:00

66 lines
1.8 KiB
Go

// Code generated by "enumer -type=RouteProtocol -linecomment -text"; DO NOT EDIT.
//
package nethelpers
import (
"fmt"
)
const _RouteProtocolName = "unspecredirectkernelbootstatic"
var _RouteProtocolIndex = [...]uint8{0, 6, 14, 20, 24, 30}
func (i RouteProtocol) String() string {
if i >= RouteProtocol(len(_RouteProtocolIndex)-1) {
return fmt.Sprintf("RouteProtocol(%d)", i)
}
return _RouteProtocolName[_RouteProtocolIndex[i]:_RouteProtocolIndex[i+1]]
}
var _RouteProtocolValues = []RouteProtocol{0, 1, 2, 3, 4}
var _RouteProtocolNameToValueMap = map[string]RouteProtocol{
_RouteProtocolName[0:6]: 0,
_RouteProtocolName[6:14]: 1,
_RouteProtocolName[14:20]: 2,
_RouteProtocolName[20:24]: 3,
_RouteProtocolName[24:30]: 4,
}
// RouteProtocolString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func RouteProtocolString(s string) (RouteProtocol, error) {
if val, ok := _RouteProtocolNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to RouteProtocol values", s)
}
// RouteProtocolValues returns all values of the enum
func RouteProtocolValues() []RouteProtocol {
return _RouteProtocolValues
}
// IsARouteProtocol returns "true" if the value is listed in the enum definition. "false" otherwise
func (i RouteProtocol) IsARouteProtocol() bool {
for _, v := range _RouteProtocolValues {
if i == v {
return true
}
}
return false
}
// MarshalText implements the encoding.TextMarshaler interface for RouteProtocol
func (i RouteProtocol) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface for RouteProtocol
func (i *RouteProtocol) UnmarshalText(text []byte) error {
var err error
*i, err = RouteProtocolString(string(text))
return err
}