def to_bytes(self): result = bytearray(self.total_length) offset = 0 offset = Network.write_int(result, self.length, offset) offset = Network.write_int_as_byte(result, self.message_type, offset) Network.write_int(result, self.piece_index, offset) return result
def to_bytes(self): result = bytearray(self.total_length) offset = 0 offset = Network.write_int(result, self.length, offset) offset = Network.write_int_as_byte(result, self.message_type, offset) offset = Network.write_int_as_byte(result, self.type, offset) Network.write_bytes(result, self.bencoded_payload, offset) return result
def to_bytes(self): result = dict() result[b'msg_type'] = self.metadata_message_type result[b'piece'] = self.piece_index data = Bencode.bencode(result) self.length = 2 + len(data) result = bytearray(self.total_length) offset = 0 offset = Network.write_int(result, self.length, offset) offset = Network.write_int_as_byte(result, self.message_type, offset) offset = Network.write_int_as_byte(result, self.type, offset) Network.write_bytes(result, data, offset) return result
def to_bytes(self): result = dict() added_result = bytearray() flag_result = bytearray() index = 0 for uri in self.added: added_result[index:index + 6] = uri_to_bytes(uri) flag_result.append(0x10) index += 6 result[b'added'] = bytes(added_result) result[b'added.f'] = bytes(flag_result) bencoded = Bencode.bencode(result) self.length = len(bencoded) + 2 result_bytes = bytearray(self.total_length) offset = 0 offset = Network.write_int(result_bytes, self.length, offset) offset = Network.write_int_as_byte(result_bytes, self.message_type, offset) offset = Network.write_int_as_byte(result_bytes, self.type, offset) Network.write_bytes(result_bytes, bencoded, offset) return result_bytes
def to_bytes(self): result = bytearray(4) Network.write_int(result, 0, 0) return result