devicepath/pciroot.go
Melora Hugues 54794b57a4
All checks were successful
continuous-integration/drone/push Build is passing
add beginning of parser
2023-08-27 15:09:30 +02:00

47 lines
901 B
Go

package devicepath
import (
"errors"
"fmt"
"strconv"
"strings"
)
const pciRootPrefix string = "PciRoot"
type PCIRootDevicePath struct {
uid int32
}
func (prp *PCIRootDevicePath) Type() DeviceNodeType {
return ACPIDevicePath
}
func (prp *PCIRootDevicePath) SubType() DeviceNodeSubType {
return ACPISubType
}
func (prp *PCIRootDevicePath) Bytes() []byte {
return nil
}
func (prp *PCIRootDevicePath) String() string {
return fmt.Sprintf("%s(0x%x)", pciRootPrefix, prp.uid)
}
func (prp *PCIRootDevicePath) ParseString(raw string) error {
if !checkStringFormat(raw, pciRootPrefix, -1) {
return ErrMalformedString
}
args := strings.Split(raw[len(pciRootPrefix)+1:len(raw)-1], ",")
if len(args) != 1 {
return errors.New("unexpected number of arguments")
}
if uid, err := strconv.ParseInt(args[0], 0, 32); err != nil {
return err
} else {
prp.uid = int32(uid)
}
return nil
}