-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vector of bit-packed structs not measuring correctly? #91
Comments
Thanks for example! The solution would be to change MeasureSize by making it not BitPackingEnabled template<typename Config>
class BasicMeasureSize {
public:
static constexpr bool BitPackingEnabled = false;
using TConfig = Config;
using TValue = uint8_t; Or, you can also try template<typename S>
void serialize(S& serializer, EntityUpdate& entityUpdate)
{
serializer.enableBitPacking([&entityUpdate](typename S::BPEnabledType& sbp) {
sbp.container(entityUpdate.inputs,
static_cast<std::size_t>(1000));
});
} Just for the record. |
That makes sense, thanks for the answer! |
in this particular example, it makes sense to add enableBitPacking in outer scope, because it allows writing inputs tightly, without aligning after each container element, and you save from 1byte (5 to 4). However if you would also write more data that doesn't require bit packing, it might be less efficient, because data might not be aligned to whole byte. (although you can call
Btw, I'm planning to change MeasureSize, so it is not EnableBitPacking by default, as it definitely confuses users. |
I think I'm starting to understand. So if I had something like the following structs:
Would I be able to get Input::inputStates to be packed properly while letting the other fields be as fast as normal by using align as so?
|
Yes, that's right. // only works if called with BPEnabled serializer/deserializer
template<typename S>
void serialize(S& serializer, Input& input)
{
serializer.container(input.inputStates, [](S& s,
Input::State& inputState) {
constexpr bitsery::ext::ValueRange<Input::State> range{
Input::State::Released, Input::State::Pressed};
s.ext(inputState, range);
});
serializer.adapter().align();
serializer.text1b(input.foo, 100);
}
template<typename S>
void serialize(S& serializer, EntityUpdate& entityUpdate)
{
serializer.value4b(entityUpdate.bar);
serializer.enableBitPacking([&entityUpdate](typename S::BPEnabledType& sbp) {
sbp.container(entityUpdate.inputs,
static_cast<std::size_t>(1000));
});
} |
Ah, good to know. Thank you very much, that clears up my questions! :D |
Hello, me again with a measurement problem. This time, I've learned my lesson and boiled it down to a simple example before bringing it here :D
I have the following code, where an
EntityUpdate
struct contains a vector ofInput
structs.Input
contains an array that gets bit-packed on serialization.The issue is, when the array is filled with more than 4 inputs, I'm getting different values between the measured size and the serialized size. In the example, I'm getting 4B for measured and 5B for final. 5B makes sense, since each Input can fit in 1B and the array will use 1B for its size.
Am I doing something incorrectly, or is there a bug?
The text was updated successfully, but these errors were encountered: