MCPcopy
hub / github.com/CodisLabs/codis / MarshalText

Method MarshalText

pkg/utils/bytesize/bytesize.go:52–79  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50}
51
52func (b Int64) MarshalText() ([]byte, error) {
53 if b == 0 {
54 return []byte("0"), nil
55 }
56 var abs = int64(b)
57 if abs < 0 {
58 abs = -abs
59 }
60 switch {
61 case abs%PB == 0:
62 val := b.Int64() / PB
63 return []byte(fmt.Sprintf("%dpb", val)), nil
64 case abs%TB == 0:
65 val := b.Int64() / TB
66 return []byte(fmt.Sprintf("%dtb", val)), nil
67 case abs%GB == 0:
68 val := b.Int64() / GB
69 return []byte(fmt.Sprintf("%dgb", val)), nil
70 case abs%MB == 0:
71 val := b.Int64() / MB
72 return []byte(fmt.Sprintf("%dmb", val)), nil
73 case abs%KB == 0:
74 val := b.Int64() / KB
75 return []byte(fmt.Sprintf("%dkb", val)), nil
76 default:
77 return []byte(fmt.Sprintf("%d", b.Int64())), nil
78 }
79}
80
81func (p *Int64) UnmarshalText(text []byte) error {
82 n, err := Parse(string(text))

Callers

nothing calls this directly

Calls 1

Int64Method · 0.95

Tested by

no test coverage detected