| 12 | { |
| 13 | template <class T> |
| 14 | inline int WriteBitpacked(skr_binary_writer_t* writer, T value, IntegerPackConfig<T> config) |
| 15 | { |
| 16 | SKR_ASSERT(config.min <= config.max); |
| 17 | bool valid = value >= config.min && value <= config.max; |
| 18 | SKR_ASSERT(valid); |
| 19 | SKR_ASSERT(writer->vwrite_bits); |
| 20 | |
| 21 | if (!writer->vwrite_bits) |
| 22 | { |
| 23 | SKR_LOG_ERROR(u8"vwrite_bits is not implemented. falling back to vwrite"); |
| 24 | return writer->write(&value, sizeof(T)); |
| 25 | } |
| 26 | auto bits = 64 - skr::CountLeadingZeros64(config.max - config.min); |
| 27 | if (!valid) |
| 28 | { |
| 29 | SKR_LOG_ERROR(u8"value %d is not in range [%d, %d]", value, config.min, config.max); |
| 30 | value = std::clamp(value, config.min, config.max); |
| 31 | } |
| 32 | T compressed = (value - config.min) & ((1 << bits) - 1); |
| 33 | return writer->write_bits(&compressed, bits); |
| 34 | } |
| 35 | |
| 36 | // template<class T> |
| 37 | // int WriteBitpacked(skr_binary_writer_t* writer, T value, FloatingPackConfig<T> config) |
no test coverage detected