@brief Given an alignment in bytes, and a current size of a buffer, return the number of bytes of padding required to align the next field to be added to the buffer at the desired alignment within that buffer. That is, return some padding such that (currentSize + padding) % alignment == 0 for alignment > 1. @param alignment Alignment in bytes: both 0 and 1 are accepted to mean "no alignment" @pa
| 47 | /// "no alignment" |
| 48 | /// @param currentSize Current number of bytes in a buffer |
| 49 | inline size_t computeAlignmentPadding(size_t alignment, |
| 50 | size_t currentSize) { |
| 51 | size_t ret = 0; |
| 52 | if (2 > alignment) { |
| 53 | /// No alignment requested |
| 54 | return ret; |
| 55 | } |
| 56 | auto leftover = currentSize % alignment; |
| 57 | if (leftover == 0) { |
| 58 | /// Buffer is already aligned |
| 59 | return ret; |
| 60 | } |
| 61 | /// Buffer needs some padding |
| 62 | ret = alignment - leftover; |
| 63 | return ret; |
| 64 | } |
| 65 | } // namespace common |
| 66 | } // namespace osvr |
| 67 |
no outgoing calls
no test coverage detected