summaryrefslogtreecommitdiff
path: root/src/rhctl/serial_port.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-04-19 04:20:15 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-04-19 04:20:15 (GMT)
commitf1a97d8e034bc6d38fc386388e733f90fe480ed7 (patch)
treec6aefa10b0278dd05f17f3cf58bb5d11a3c588fe /src/rhctl/serial_port.go
parent3b24e2e452178475284aa0a8240eb8b76974a153 (diff)
create marshaller/unmarshaller for text,json,toml for all special types
Diffstat (limited to 'src/rhctl/serial_port.go')
-rw-r--r--src/rhctl/serial_port.go27
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 {