-
Notifications
You must be signed in to change notification settings - Fork 0
/
units.go
54 lines (41 loc) · 1.07 KB
/
units.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package units
// Mbps is Megabits per second.
//
// https://en.wikipedia.org/wiki/Data-rate_units#Megabit_per_second
type Mbps float64
func (t *Mbps) UnmarshalText(data []byte) error {
f, err := UnmarshalFloatWithUnits(data, "Mbps")
if err != nil {
return err
}
*t = Mbps(f)
return nil
}
func (t Mbps) BitsPerSec() float64 {
return float64(t) * 1000 * 1000
}
// Decibel (dB) is a relative unit of measurement equal to one tenth of a bel (B).
//
// https://en.wikipedia.org/wiki/Decibel
type Decibel float64
func (t *Decibel) UnmarshalText(data []byte) error {
f, err := UnmarshalFloatWithUnits(data, "dB")
if err != nil {
return err
}
*t = Decibel(f)
return nil
}
// DecibelMilliwatt (dBm) is a unit of level used to indicate that a power
// level is expressed in decibels (dB) with reference to one milliwatt (mW).
//
// https://en.wikipedia.org/wiki/DBm
type DecibelMilliwatt float64
func (t *DecibelMilliwatt) UnmarshalText(data []byte) error {
f, err := UnmarshalFloatWithUnits(data, "dBm")
if err != nil {
return err
}
*t = DecibelMilliwatt(f)
return nil
}