namespace RoboidControl {
///
/// Message for sending generic text
///
public class TextMsg : IMessage {
///
/// The message ID
///
public const byte Id = 0xB0;
///
/// The length of the message without the text itself
///
public const byte length = 2;
///
/// The text
///
public string text = "";
///
/// Create a new message for sending
///
/// The text to send
public TextMsg(string text) {
this.text = text;
}
/// @copydoc Passer::RoboidControl::IMessage::IMessage(byte[] buffer)
public TextMsg(byte[] buffer) : base(buffer) { }
/// @copydoc Passer::RoboidControl::IMessage::Serialize
public override byte Serialize(ref byte[] buffer) {
if (buffer.Length < TextMsg.length + this.text.Length || this.text.Length == 0)
return 0;
byte ix = 0;
buffer[ix++] = TextMsg.Id;
buffer[ix++] = (byte)this.text.Length;
for (int textIx = 0; textIx < this.text.Length; textIx++)
buffer[ix++] = (byte)this.text[textIx];
return ix;
}
}
}