forked from zach-klippenstein/goadb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
device_descriptor.go
80 lines (68 loc) · 1.81 KB
/
device_descriptor.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package adb
import "fmt"
//go:generate stringer -type=deviceDescriptorType
type deviceDescriptorType int
const (
// host:transport-any and host:<request>
DeviceAny deviceDescriptorType = iota
// host:transport:<serial> and host-serial:<serial>:<request>
DeviceSerial
// host:transport-usb and host-usb:<request>
DeviceUsb
// host:transport-local and host-local:<request>
DeviceLocal
)
type DeviceDescriptor struct {
descriptorType deviceDescriptorType
// Only used if Type is DeviceSerial.
serial string
}
func AnyDevice() DeviceDescriptor {
return DeviceDescriptor{descriptorType: DeviceAny}
}
func AnyUsbDevice() DeviceDescriptor {
return DeviceDescriptor{descriptorType: DeviceUsb}
}
func AnyLocalDevice() DeviceDescriptor {
return DeviceDescriptor{descriptorType: DeviceLocal}
}
func DeviceWithSerial(serial string) DeviceDescriptor {
return DeviceDescriptor{
descriptorType: DeviceSerial,
serial: serial,
}
}
func (d DeviceDescriptor) String() string {
if d.descriptorType == DeviceSerial {
return fmt.Sprintf("%s[%s]", d.descriptorType, d.serial)
}
return d.descriptorType.String()
}
func (d DeviceDescriptor) getHostPrefix() string {
switch d.descriptorType {
case DeviceAny:
return "host"
case DeviceUsb:
return "host-usb"
case DeviceLocal:
return "host-local"
case DeviceSerial:
return fmt.Sprintf("host-serial:%s", d.serial)
default:
panic(fmt.Sprintf("invalid DeviceDescriptorType: %v", d.descriptorType))
}
}
func (d DeviceDescriptor) getTransportDescriptor() string {
switch d.descriptorType {
case DeviceAny:
return "transport-any"
case DeviceUsb:
return "transport-usb"
case DeviceLocal:
return "transport-local"
case DeviceSerial:
return fmt.Sprintf("transport:%s", d.serial)
default:
panic(fmt.Sprintf("invalid DeviceDescriptorType: %v", d.descriptorType))
}
}