private Message(byte[] bytes) { var bytesAsList = bytes.ToList(); Type = (PeerCommandType)bytes[0]; const int startHeadIndex = 1; var endHeadIndex = FindBytesIndex(bytes, END_HEAD_DELIMITER); var endIndex = FindBytesIndex(bytes, END_DELIMITER); var startBodyIndex = endHeadIndex + END_HEAD_DELIMITER.Length; head = bytesAsList.GetRange(startHeadIndex, endHeadIndex - startHeadIndex).ToArray(); body = bytesAsList.GetRange(startBodyIndex, endIndex - startBodyIndex).ToArray(); }
protected Message(Message message) { Type = message.Type; head = message.head; body = message.body; }
public Message(PeerCommandType type) { Type = type; head = new byte[0]; body = new byte[0]; }