1 Star 0 Fork 0

叶海丰/ipmi-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cmd_raw.go 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
叶海丰 提交于 12个月前 . init
package ipmi
import (
"fmt"
"strings"
)
type CommandRawRequest struct {
NetFn NetFn
Cmd uint8
Data []byte
Name string
}
type CommandRawResponse struct {
Response []byte
}
func (req *CommandRawRequest) Command() Command {
return Command{ID: req.Cmd, NetFn: req.NetFn, Name: req.Name}
}
func (req *CommandRawRequest) Pack() []byte {
out := make([]byte, len(req.Data))
packBytes(req.Data, out, 0)
return out
}
func (res *CommandRawResponse) Unpack(msg []byte) error {
res.Response = msg
return nil
}
func (res *CommandRawResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{}
}
func (res *CommandRawResponse) Format() string {
// convert the byte array to a slice of hex strings
hexStrings := make([]string, len(res.Response))
for i, b := range res.Response {
hexStrings[i] = fmt.Sprintf("0x%02X", b)
}
// join the hex strings with commas
hexString := strings.Join(hexStrings, ", ")
return fmt.Sprintf(`raw.Response = %s`, hexString)
}
func (c *Client) RawCommand(netFn NetFn, cmd uint8, data []byte, name string) (response *CommandRawResponse, err error) {
request := &CommandRawRequest{
NetFn: netFn,
Cmd: cmd,
Data: data,
Name: name,
}
response = &CommandRawResponse{}
err = c.Exchange(request, response)
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/rogax/ipmi-go.git
git@gitee.com:rogax/ipmi-go.git
rogax
ipmi-go
ipmi-go
86ae46cfb58e

搜索帮助