/* */ #include "RangeBtMessage.h" #include "util.h" #include "a2functional.h" #include "bittorrent_helper.h" namespace aria2 { RangeBtMessage::RangeBtMessage(uint8_t id, const std::string& name, size_t index, uint32_t begin, size_t length) :SimpleBtMessage(id, name), index_(index), begin_(begin), length_(length) {} unsigned char* RangeBtMessage::createMessage() { /** * len --- 13, 4bytes * id --- ?, 1byte * index --- index, 4bytes * begin --- begin, 4bytes * length -- length, 4bytes * total: 17bytes */ unsigned char* msg = new unsigned char[MESSAGE_LENGTH]; bittorrent::createPeerMessageString(msg, MESSAGE_LENGTH, 13, getId()); bittorrent::setIntParam(&msg[5], index_); bittorrent::setIntParam(&msg[9], begin_); bittorrent::setIntParam(&msg[13], length_); return msg; } size_t RangeBtMessage::getMessageLength() { return MESSAGE_LENGTH; } std::string RangeBtMessage::toString() const { return strconcat(getName(), " index=", util::uitos(index_), ", begin=", util::uitos(begin_), ", length=", util::uitos(length_)); } } // namespace aria2