The Way to Programming
The Way to Programming
// write 90 bytes memcpy(buf,packet_buffer + written, 90); // could also use 'snprintf()', won't terminate iether buf[91] = '\0'; // zero-terminate buffer
The buffer terminates at buf[91] what means it is the 92th byte. so after 90 characters the buffer contains 1 byte with random contents. also if the print function expects a 90-byte buffer, it is probably too much to pass 92 bytes since it might write beyond buffer boundaries in the print function by 1 or two bytes.
so the code should be
char buf[90] = { '\0' }; // initialize the buffer for (written = 0; written < packet_size - remainder; written += 89) { // copy 89 bytes (or less at end) int ncopy = min(89, packet_size-remainder-written); memcpy(buf, packet_buffer + written, ncopy); buf[ncopy] = '\0'; // zero-terminate buffer in 90th byte (is buf[89])
Would calling your print utility in a loop until all the packed is dumped be be an option or is there an issue with that? E.g. like
unsigned int written = 0; for (written = 0; i < packet_size - packet_size % 90; written += 90) { // write 90 bytes log_3rd_party(packet_buffer + written, 90); } // log the remainder log_3rd_party(packet_buffer + written, packet_size % 90);
As you also asked where you want to instantiate this model, it depend on your requirement. Please read the page life cycle and understand then you can easily decide yourself as per your requirement.
https://msdn.microsoft.com/en-us/library/ms178472.aspx
Sign in to your account