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

Fails to compile when asked to serialize a struct that contains a char array #53

Open
marlowa opened this issue Dec 28, 2024 · 2 comments

Comments

@marlowa
Copy link

marlowa commented Dec 28, 2024

Here is the code:

`#include <alpaca/alpaca.h>

struct StartPacket
{
int32_t byteCount;
char magic[4];
};

int main()
{
StartPacket startPacket;
std::vector<uint8_t> buffer;
auto size = alpaca::serialize(startPacket, buffer);
return 0;
}
`

and here is the compilation error:

In file included from thirdparty/alpaca/include/alpaca/alpaca.h:9, from serialise.cpp:1: thirdparty/alpaca/include/alpaca/detail/struct_nth_field.h: In instantiation of ‘constexpr decltype(auto) alpaca::detail::get(type&) [with long unsigned int index = 0; type = const StartPacket&; long unsigned int arity = 5]’: thirdparty/alpaca/include/alpaca/alpaca.h:137:60: required from ‘void alpaca::detail::serialize_helper(const T&, Container&, std::size_t&) [with alpaca::options O = alpaca::options::none; T = StartPacket; long unsigned int N = 5; Container = std::vector<unsigned char>; long unsigned int I = 0; std::size_t = long unsigned int]’ thirdparty/alpaca/include/alpaca/alpaca.h:169:62: required from ‘std::size_t alpaca::serialize(const T&, Container&) [with T = StartPacket; long unsigned int N = 5; Container = std::vector<unsigned char>; std::size_t = long unsigned int]’ serialise.cpp:13:54: required from here thirdparty/alpaca/include/alpaca/detail/struct_nth_field.h:54:11: error: 5 names provided for structured binding 54 | auto &[p1, p2, p3, p4, p5] = value; | ^~~~~~~~~~~~~~~~~~~~ thirdparty/alpaca/include/alpaca/detail/struct_nth_field.h:54:11: note: while ‘const StartPacket’ decomposes into 2 elements In file included from serialise.cpp:1: thirdparty/alpaca/include/alpaca/alpaca.h: In instantiation of ‘void alpaca::detail::serialize_helper(const T&, Container&, std::size_t&) [with alpaca::options O = alpaca::options::none; T = StartPacket; long unsigned int N = 5; Container = std::vector<unsigned char>; long unsigned int I = 0; std::size_t = long unsigned int]’: thirdparty/alpaca/include/alpaca/alpaca.h:169:62: required from ‘std::size_t alpaca::serialize(const T&, Container&) [with T = StartPacket; long unsigned int N = 5; Container = std::vector<unsigned char>; std::size_t = long unsigned int]’ serialise.cpp:13:54: required from here thirdparty/alpaca/include/alpaca/alpaca.h:137:20: error: ‘void field’ has incomplete type 137 | decltype(auto) field = detail::get<I, decltype(ref), N>(ref); | ^~~~~

This seems like a bug to me. This is with the latest alpaca code via git clone as of 2024-12-28.

@lrodorigo
Copy link

struct StartPacket
{
int32_t byteCount;
std::array<char,4> magic;
};

and it is just working.

@marlowa
Copy link
Author

marlowa commented Mar 4, 2025

Thank you for your reply. Using std::array instead of old style C arrays is obviously much better. However, I think that something has to change. Either alpaca is changed so that the use of C arrays works (i.e. fix that compilation error), or alpaca documentation needs to say that C arrays are not supported and std::array should be used instead.

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

No branches or pull requests

2 participants