Skip to content
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

Integer value problem #16

Open
mengguang opened this issue Feb 20, 2023 · 2 comments
Open

Integer value problem #16

mengguang opened this issue Feb 20, 2023 · 2 comments

Comments

@mengguang
Copy link

I copyed the sample code and just change the value of c to UINT64_MAX, the assert failed.

#include <alpaca/alpaca.h>

int main() {

    struct MyStruct {
        char a;
        int b;
        uint64_t c;
        float d;
        bool e;
    };

    MyStruct s{ 'a', 5, UINT64_MAX, 3.14f, true };

    // Serialize
    std::vector<uint8_t> bytes;
    auto bytes_written = alpaca::serialize(s, bytes);

    // Deserialize
    std::error_code ec;
    auto recovered = alpaca::deserialize<MyStruct>(bytes, ec);
    assert((bool)ec == false);
    assert(recovered.a == 'a');
    assert(recovered.b == 5);
    assert(recovered.c == UINT64_MAX);
    assert(recovered.d == 3.14f);
    assert(recovered.e == true);
}

Is this a problem? My test environment is msvc2022.
I also tested the same code in Ubuntu 20.04.4 LTS and g++ version 9.4.0 , same result.

@marlowa
Copy link

marlowa commented Dec 27, 2024

This looks like a serious problem to me. I am hunting for a modern C++ library for serialise/deserialise and came across this one, but this bug would be a showstopper. The code I am working with employs structures where 64 bit unsigned integers take the maximum permitted value to indicate that the value is not there. I know that's horrible, but there's nothing I can do about it. But it is why this bug would need to be fixed before I could use the library.

@lrodorigo
Copy link

lrodorigo commented Jan 24, 2025

The variable length encoding is still totally broken.
However thanks to last merged pull requests (like #45), the fixed length encoding is properly working and it is architecture independent, I am using the library and it is working pretty well...

Just use

constexpr auto OPTIONS = options::fixed_length_encoding;
std::vector<uint8_t> bytes;
alpaca::serialize<OPTIONS>(data, bytes);

when serializing and deserializing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants