// Command sends a command and returns the response from QEMU.
Command sends a command and returns the response from QEMU.
// Command sends a command and returns the response from QEMU .
func (s Session) Command(command string, arguments map[string]interface{}) (JsonValue, error) {
	cmd := make(JsonObject)
	cmd["execute"] = command
	if arguments != nil {
		cmd["arguments"] = arguments
	}
	err := json.NewEncoder(s.c).Encode(cmd)
	if err != nil {
		return nil, fmt.Errorf("qmp: encode json: %s", err)
	}
	t, data, err := s.read()
	if err != nil {
		return nil, err
	}
	if t == MessageTypeSuccess {
		var m SuccessMessage
		err := json.Unmarshal(data, &m)
		if err != nil {
			return nil, fmt.Errorf("qmp: decode json error: %s", err)
		}
		return m.Return, nil
	} else if t == MessageTypeError {
		var e ErrorMessage
		err := json.Unmarshal(data, &e)
		if err != nil {
			return nil, fmt.Errorf("qmp: decode json error: %s", err)
		}
		return nil, fmt.Errorf("qmp error %s: %s", e.Error.Class, e.Error.Desc)
	}
	return nil, fmt.Errorf("qmp: unknown message")
}
func ( s Session ) Command ( command string , arguments map [ string ] interface { } ) ( JsonValue , error ) { cmd := make ( JsonObject ) cmd [ " " ] = command if arguments != nil { cmd [ " " ] = arguments } err := json . NewEncoder ( s . c ) . Encode ( cmd ) if err != nil { return nil , fmt . Errorf ( " " , err ) } t , data , err := s . read ( ) if err != nil { return nil , err } if t == MessageTypeSuccess { var m SuccessMessage err := json . Unmarshal ( data , & m ) if err != nil { return nil , fmt . Errorf ( " " , err ) } return m . Return , nil } else if t == MessageTypeError { var e ErrorMessage err := json . Unmarshal ( data , & e ) if err != nil { return nil , fmt . Errorf ( " " , err ) } return nil , fmt . Errorf ( " " , e . Error . Class , e . Error . Desc ) } return nil , fmt . Errorf ( " " ) }
Command sends a command and returns the response from QEMU.
Command sends a command and returns the response from QEMU .