This commit is contained in:
20
size_text.go
Normal file
20
size_text.go
Normal file
@@ -0,0 +1,20 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user