Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#3233 closed Bugs (wontfix)

serialization problem: enum : __int64

Reported by: dcb_BanDos <ban_dos@…> Owned by: Robert Ramey
Milestone: Boost 1.40.0 Component: serialization
Version: Boost 1.39.0 Severity: Problem
Keywords: __int64 enum serialization Cc:

Description

I have a enum and structure:

typedef enum : unsigned __int64 {
    epUnknown = 0x0,
        epCpuSystem =    0x0001LL,
....
         epAvgCpu=    0x100000000LL
}  CGenericParamParam;

struct fee
{
....
 CGenericParamParam param;
}

Then i try to serialize this structure into boost::archive::binary_oarchive via boost::serialization:

template<class Archive, class T>
struct save_enum_type
{
    static void invoke(Archive &ar, const T &t){
        // convert enum to integers on save
        const int i = static_cast<int>(t);
        ar << boost::serialization::make_nvp(NULL, i);
    }
};

Casting 0x100000000LL

into int gives 0.

Any ideas?

Change History (2)

comment:1 by Robert Ramey, 13 years ago

Resolution: wontfix
Status: newclosed

this would make binary archives larger for every user of the library. And also require code to recognise old archives. All in all just not worth it. Try something like

enum {

epAvgCpu

... } const int_64 lookup_table[] = { 0x10000000l ...

and use

lookup_table[epAvgCpu instead of epAvgCpu.

comment:2 by Dmitry <ban_dos@…>, 13 years ago

namespace boost
{
        namespace archive
        {
                namespace detail
                {
                        template<class Archive>
                        struct save_enum_type<Archive, CGenericParamParam>
                        {
                                static void invoke(Archive &ar, const  CGenericParamParam & param)
                                {
                                        // convert enum to integers on save
                                        const __int64 i = static_cast<__int64>( param );
                                        ar << boost::serialization::make_nvp(NULL, i);
                                }
                        };

                        template<class Archive>
                        struct load_enum_type<Archive, CGenericParamParam> 
                        {
                                static void invoke(Archive &ar, CGenericParamParam & param)
                                {
                                        // convert integers to correct enum to load
                                        __int64 i = 0;
                                        ar >> boost::serialization::make_nvp(NULL, i);
                                        param = static_cast<CGenericParamParam>(i);
                                }
                        };
                }
        }
}
Note: See TracTickets for help on using tickets.