diff options
Diffstat (limited to 'src/rhctl/serial_port.go')
-rw-r--r-- | src/rhctl/serial_port.go | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/rhctl/serial_port.go b/src/rhctl/serial_port.go index 7a0af2c..5440f99 100644 --- a/src/rhctl/serial_port.go +++ b/src/rhctl/serial_port.go @@ -45,6 +45,21 @@ func (b Baudrate) String() string { return strconv.FormatUint(uint64(b.value), 10) } +func (b Baudrate) MarshalText() (data []byte, err error) { + data = []byte(b.String()) + return +} + +func (b Baudrate) MarshalJSON() (data []byte, err error) { + data = []byte(b.String()) + return +} + +func (b Baudrate) MarshalTOML() (data []byte, err error) { + data = []byte(b.String()) + return +} + func (b *Baudrate) FromUint(value uint32) error { b.value = value switch b.value { @@ -114,7 +129,7 @@ func (b *Baudrate) FromUint(value uint32) error { return nil } -func (b *Baudrate) FromString(str string) error { +func (b *Baudrate) fromString(str string) error { vuint, err := strconv.ParseUint(str, 10, 32) if err != nil { return err @@ -122,8 +137,16 @@ func (b *Baudrate) FromString(str string) error { return b.FromUint(uint32(vuint)) } +func (b *Baudrate) UnmarshalText(data []byte) error { + return b.fromString(string(data)) +} + +func (b *Baudrate) UnmarshalJSON(data []byte) error { + return b.fromString(string(data)) +} + func (b *Baudrate) UnmarshalTOML(data []byte) error { - return b.FromString(string(data)) + return b.fromString(string(data)) } type SerialPort struct { |