Convert a structure to ASN1_OCTET_STRING - Openssl

This is a discussion on Convert a structure to ASN1_OCTET_STRING - Openssl ; Hi,
I need to send a structure between a client and a server, but I don't know what that structure will be until run-time, so I decided to send the structure as ASN1_OCTET_STRING, along with a type that tells me ...

Convert a structure to ASN1_OCTET_STRING

Hi,

I need to send a structure between a client and a server, but I don't know what that structure will be until run-time, so I decided to send the structure as ASN1_OCTET_STRING, along with a type that tells me what the structure is. Is it safe to static cast the pointer to the structure to unsigned char* and send this pointer as a parameter to ASN1_OCTET_STRING_set function along with it's length? I tried with various structures but it fails when the structure contains stacks.