BxCmdFileDelete.go 837 B

123456789101112131415161718192021222324252627282930313233343536
  1. package bx
  2. import (
  3. "bytes"
  4. "encoding/binary"
  5. )
  6. type CmdDeleteFile struct {
  7. baseBxCmd
  8. files []string
  9. }
  10. func NewCmdDeleteFile(files []string) CmdDeleteFile {
  11. return CmdDeleteFile{
  12. baseBxCmd: newBaseCmd(CMD_DEL_FILE.group, CMD_DEL_FILE.code),
  13. files: files,
  14. }
  15. }
  16. func (cmd CmdDeleteFile) Build() []byte {
  17. w := bytes.NewBuffer(make([]byte, 0, 1024))
  18. binary.Write(w, binary.LittleEndian, cmd.Group())
  19. binary.Write(w, binary.LittleEndian, cmd.Cmd())
  20. binary.Write(w, binary.LittleEndian, cmd.ReqResp())
  21. binary.Write(w, binary.LittleEndian, []byte{0x00, 0x00})
  22. l := uint16(len(cmd.files))
  23. if l != 0 {
  24. binary.Write(w, binary.LittleEndian, l)
  25. for _, v := range cmd.files {
  26. binary.Write(w, binary.BigEndian, []byte(v))
  27. }
  28. return w.Bytes()
  29. }
  30. binary.Write(w, binary.LittleEndian, []byte{0x00})
  31. return w.Bytes()
  32. }