21 lines
302 B
Go
21 lines
302 B
Go
package bytesize
|
|
|
|
import "fmt"
|
|
|
|
func (s Size) MarshalText() ([]byte, error) {
|
|
val := s.String()
|
|
|
|
return []byte(val), nil
|
|
}
|
|
|
|
func (s *Size) UnmarshalText(text []byte) error {
|
|
val, err := Parse(string(text))
|
|
if err != nil {
|
|
return fmt.Errorf("%w: unmarshal text", err)
|
|
}
|
|
|
|
*s = val
|
|
|
|
return nil
|
|
}
|