CAF Serialization & union

29 views
Skip to first unread message

Ventura Del Monte

unread,
Nov 16, 2019, 5:29:58 AM11/16/19
to actor-framework
Hi all,

I have played with CAF for a while now and I must say it is a nice framework. 
I am writing on this ML because i run into an issue with CAF's serialization stack.
I am serializing a POD (struct) that contains an union type. I overloaded the inspect 
template function for both PODs but for some reasons the data processor of CAF cannot 
see the inspect function for the union type. I checked the examples and the UT for 
CAF serialization, and it seems union are not handled. I have always assumed that an
union is just like a struct but maybe I am missing something. Could you please help me 
to figure out this issue?
Thank you in advance for your help.

Best,
Ventura

Dominik Charousset

unread,
Nov 21, 2019, 10:37:39 AM11/21/19
to actor-f...@googlegroups.com
Hi,

> I have played with CAF for a while now and I must say it is a nice framework.

always great to see new people on the list. :)

> I am writing on this ML because i run into an issue with CAF's serialization stack.
> I am serializing a POD (struct) that contains an union type. I overloaded the inspect
> template function for both PODs but for some reasons the data processor of CAF cannot
> see the inspect function for the union type. I checked the examples and the UT for
> CAF serialization, and it seems union are not handled. I have always assumed that an
> union is just like a struct but maybe I am missing something. Could you please help me
> to figure out this issue?
> Thank you in advance for your help.

There’s no generic way of dealing with a union, because CAF cannot know which type of the union is currently active. Just serializing the bits isn’t safe for numerous reasons (big/little endian conversion, handle types such as string, etc.). A union always comes with some sort of tag to tell at runtime which value is currently present. If this is code you’re in control of, I suggest using a variant<...> instead. If you are dealing with legacy or C code, then you’ll have to implement an inspect() functions to deal with your type.

Hope that helps,
Dominik

Ventura Del Monte

unread,
Nov 22, 2019, 4:36:45 AM11/22/19
to actor-framework
Hi,

Thank you for your reply. I did as you suggested and it works now. I actually had another mistake in my code, i.e., I somehow missed that I must register my data types using 'add_message_type'.

Best,
Ventura
Reply all
Reply to author
Forward
0 new messages