forked from bougou/go-ipmi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_get_username.go
47 lines (38 loc) · 1.03 KB
/
cmd_get_username.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
package ipmi
import "bytes"
// 22.29 Get User Name Command
type GetUsernameRequest struct {
// [5:0] - User ID. 000000b = reserved. (User ID 1 is permanently associated with User 1, the null user name).
UserID uint8
}
type GetUsernameResponse struct {
Username string
}
func (req *GetUsernameRequest) Command() Command {
return CommandGetUsername
}
func (req *GetUsernameRequest) Pack() []byte {
return []byte{req.UserID}
}
func (res *GetUsernameResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{}
}
func (res *GetUsernameResponse) Unpack(msg []byte) error {
if len(msg) < 16 {
return ErrUnpackedDataTooShort
}
username, _, _ := unpackBytes(msg, 0, 16)
res.Username = string(bytes.TrimRight(username, "\x00"))
return nil
}
func (res *GetUsernameResponse) Format() string {
return ""
}
func (c *Client) GetUsername(userID uint8) (response *GetUsernameResponse, err error) {
request := &GetUsernameRequest{
UserID: userID,
}
response = &GetUsernameResponse{}
err = c.Exchange(request, response)
return
}