So I'm trying to use ns-3 to do some network simulations. I want to transfer a file (which can be quite big, some video file for example), so I have to "pack" the file in the data structure provided by the framework
ns3::Packet::Packet ( uint8_t const * buffer, uint32_t size )
So I need to have my file serialized to a uint8_t buffer - I've tried this so far:
std::ifstream input_sample_file("sample_input_file.mp4",std::ifstream::out | std::ifstream::binary);
std::ofstream output_sample_file("sample_output_file.mp4",std::ifstream::binary | std::ifstream::in );
long sample_file_size;
sample_file_size = getFileSize(input_sample_file);
char * sample_buffer = new char [sample_file_size];
input_sample_file.read(sample_buffer, sample_file_size);
uint8_t * sample_buffer_adjusted = new uint8_t [sample_file_size];
std::memcpy(&sample_buffer_adjusted, (const char *) sample_buffer, sample_file_size);
Which of course is very inefficient in the first place, and of course the memcpy
fails, which shouldn't be much of a surprise, but I haven't tried to fix this, because there has to be some other way to directly serialize the input file to a uint8_t
buffer, and then hand it over to ns3::Packet::Packet
.