Files
ReArchive/src/types/FileEntry.cpp
2025-02-16 22:39:39 -05:00

39 lines
1.1 KiB
C++

#include <ReArchive/types/FileEntry.h>
#include <cstring>
using namespace ReArchive;
std::vector<unsigned char> FileEntry::Serialize(const FileEntry& file) {
std::string path_string = file.path.string();
int64_t path_size = path_string.size();
std::vector<unsigned char> result(sizeof(int64_t) + path_size + 2 * sizeof(int64_t));
unsigned char* ptr = result.data();
auto network_path_size = htobe64(path_size);
memcpy(ptr, &network_path_size, sizeof(int64_t));
ptr += sizeof(int64_t);
memcpy(ptr, path_string.data(), path_size);
ptr += path_size;
auto network_data_size = htobe64(file.data_size);
memcpy(ptr, &network_data_size, sizeof(int64_t));
ptr += sizeof(int64_t);
auto network_data_offset = htobe64(file.data_offset);
memcpy(ptr, &network_data_offset, sizeof(int64_t));
return result;
}
bool FileEntry::operator==(const FileEntry& rhs) const {
if (data_offset != rhs.data_offset)
return false;
if (data_size != rhs.data_size)
return false;
if (path != rhs.path)
return false;
return true;
}