MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / WriteBitpacked

Function WriteBitpacked

modules/engine/runtime/serde/binary/writer.cpp:14–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12{
13template <class T>
14inline 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)

Callers 1

WriteMethod · 0.85

Calls 8

IntTypeClass · 0.85
CountLeadingZeros64Function · 0.50
isnanFunction · 0.50
maxFunction · 0.50
absFunction · 0.50
minFunction · 0.50
writeMethod · 0.45
write_bitsMethod · 0.45

Tested by

no test coverage detected