BxCmdDelDynamicArea.go 857 B

123456789101112131415161718192021222324252627282930313233343536
  1. package bx
  2. import (
  3. "bytes"
  4. "encoding/binary"
  5. )
  6. type CmdDelDynamicArea struct {
  7. baseBxCmd
  8. numbers []byte //编号
  9. }
  10. func NewCmdDelDynamicArea(numbers []byte) CmdDelDynamicArea {
  11. return CmdDelDynamicArea{
  12. baseBxCmd: newBaseCmd(CMD_DEL_DYNAMIC_AREA.group, CMD_DEL_DYNAMIC_AREA.code),
  13. numbers: numbers,
  14. }
  15. }
  16. func (cmd CmdDelDynamicArea) Build() []byte {
  17. w := bytes.NewBuffer(make([]byte, 0, 16))
  18. binary.Write(w, binary.LittleEndian, cmd.Group())
  19. binary.Write(w, binary.LittleEndian, cmd.Cmd())
  20. binary.Write(w, binary.LittleEndian, byte(0x01))
  21. binary.Write(w, binary.LittleEndian, []byte{0x00, 0x00})
  22. l := byte(len(cmd.numbers))
  23. if l == 0 {
  24. binary.Write(w, binary.LittleEndian, 0xff)
  25. } else {
  26. binary.Write(w, binary.LittleEndian, l)
  27. }
  28. for _, n := range cmd.numbers {
  29. binary.Write(w, binary.LittleEndian, n)
  30. }
  31. return w.Bytes()
  32. }