package devicepath import ( "errors" "fmt" "strconv" "strings" ) const ipv6Prefix string = "IPv6" type Ipv6DevicePath struct { remoteIP string protocol string static bool } func (ip *Ipv6DevicePath) Type() DeviceNodeType { return MessagingDevicePath } func (ip *Ipv6DevicePath) SubType() DeviceNodeSubType { return IPv6MessagingSubType } func (ip *Ipv6DevicePath) Bytes() []byte { return nil } func (ip *Ipv6DevicePath) String() string { ipType := 0 if ip.static { ipType = 1 } return fmt.Sprintf("%s(%s,%s,%d)", ipv6Prefix, ip.remoteIP, ip.protocol, ipType) } func (ip *Ipv6DevicePath) ParseString(raw string) error { if !checkStringFormat(raw, ipv6Prefix, -1) { return ErrMalformedString } args := strings.Split(raw[len(ipv6Prefix)+1:len(raw)-1], ",") if len(args) != 3 { return errors.New("unexpected number of arguments") } ip.remoteIP = args[0] ip.protocol = args[1] if ipType, err := strconv.Atoi(args[2]); err != nil { return err } else { ip.static = ipType == 1 } return nil }