com.mytechia.robobo.rob.comm.ChangeNameMessage Maven / Gradle / Ivy
Show all versions of robobo-rob-interface Show documentation
/**
* *****************************************************************************
*
* Copyright (C) 2017 Mytech Ingenieria Aplicada
* Copyright (C) 2017 Victor Sonora Pombo
*
* This file is part of Luminare360 Firmware.
* ****************************************************************************
*/
package com.mytechia.robobo.rob.comm;
import com.mytechia.commons.framework.simplemessageprotocol.MessageCoder;
import com.mytechia.commons.framework.simplemessageprotocol.MessageDecoder;
import com.mytechia.commons.framework.simplemessageprotocol.exception.MessageFormatException;
/**
* Created by victorsonorapombo.
*/
public class ChangeNameMessage extends RoboCommand {
private String name;
public ChangeNameMessage(String name) {
super();
this.setCommandType(MessageType.ChangeBtNameMessage.commandType);
this.name = name;
}
public ChangeNameMessage(byte [] messageData) throws MessageFormatException {
super(messageData);
this.setCommandType(MessageType.ChangeBtNameMessage.commandType);
}
@Override
protected byte[] codeMessageData() throws MessageFormatException {
MessageCoder messageCoder = this.getMessageCoder();
//messageCoder.writeString(this.name, "name");
messageCoder.writeByteArray(this.name.getBytes(), "name");
return messageCoder.getBytes();
}
@Override
protected int decodeMessageData(byte[] bytes, int i) throws MessageFormatException {
MessageDecoder messageDecoder = this.getMessageDecoder();
final byte[] nameBytes = messageDecoder.readByteArray("name");
this.name = new String(nameBytes);
return this.getMessageDecoder().getArrayIndex();
}
public String getName() {
return this.name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ChangeNameMessage that = (ChangeNameMessage) o;
return name != null ? name.equals(that.name) : that.name == null;
}
@Override
public int hashCode() {
return name != null ? name.hashCode() : 0;
}
}