Merge pull request #10 from dron0gus/fragments-return

copyRange(): return actual data copies (wthout zero filled)
This commit is contained in:
rusefillc 2023-08-27 12:37:34 -07:00 committed by GitHub
commit 5f11cb156e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -48,7 +48,7 @@ struct FragmentList {
};
// copy `size` of fragmented outputs in to destination, skipping the first `skip` bytes
void copyRange(uint8_t* destination, FragmentList src, size_t skip, size_t size);
size_t copyRange(uint8_t* destination, FragmentList src, size_t skip, size_t size);
// returns pointer to actual data and size of contiguous data
// if data is located in more than one fragmnet - returned value will be size available in first fragment
size_t getRangePtr(uint8_t **ptr, FragmentList src, size_t offset, size_t size);

View File

@ -10,7 +10,7 @@
#include <rusefi/math.h>
#include <cstring>
void copyRange(uint8_t* destination, FragmentList src, size_t skip, size_t size) {
size_t copyRange(uint8_t* destination, FragmentList src, size_t skip, size_t size) {
size_t fragmentIndex = 0;
// Find which fragment to start - skip any full fragments smaller than `skip` parameter
@ -25,7 +25,7 @@ void copyRange(uint8_t* destination, FragmentList src, size_t skip, size_t size)
if (fragmentIndex >= src.count) {
// somehow we are past the end of fragments - fill with zeros
memset(destination + destinationIndex, 0, size);
return;
return destinationIndex;
}
int copyNowSize = minI(size, src.fragments[fragmentIndex].size - skip);
@ -41,6 +41,7 @@ void copyRange(uint8_t* destination, FragmentList src, size_t skip, size_t size)
size -= copyNowSize;
fragmentIndex++;
}
return destinationIndex;
}
size_t getRangePtr(uint8_t **ptr, FragmentList src, size_t offset, size_t size)