简体   繁体   中英

Serializing TAO/CORBA objects with boost::serialization

I have a problem with serializing classes generated by corba - especially with any kind of sequences - TAO::unbouded_value_sequence, TAO::unbouded_basic_string_sequence, etc.

Is there any "good" solution for serialization of CORBA structures or do I have reverse engineer the code of corba clases and try to write serialization funtion for each of them?

EDIT:

      struct Something;

      typedef
        TAO_Var_Var_T<
            Something
          >
        Something_var;

      typedef
        TAO_Out_T<
            Something
          >
        Something_out;


      struct  Something
      {
        typedef Something_var _var_type;
        typedef Something_out _out_type;

        static void _tao_any_destructor (void *);
        TAO::String_Manager member1;
      };
    class SequenceOfSomething;

  typedef
    TAO_VarSeq_Var_T<
        SequenceOfSomething
      >
    SequenceOfSomething_var;

  typedef
    TAO_Seq_Out_T<
        SequenceOfSomething
      >
    SequenceOfSomething_out;

  class  SequenceOfSomething
    : public
        TAO::unbounded_value_sequence<
            Something
          >
  {
  public:
    SequenceOfSomething (void);
    SequenceOfSomething ( ::CORBA::ULong max);
    SequenceOfSomething (
        ::CORBA::ULong max,
        ::CORBA::ULong length,
        SequenceOfSomething* buffer, 
        ::CORBA::Boolean release = false
      );
    SequenceOfSomething (const SequenceOfSomething &);
    virtual ~SequenceOfSomething (void);

    static void _tao_any_destructor (void *);

    typedef SequenceOfSomething_var _var_type;
    typedef SequenceOfSomething_out _out_type;


  };

This is some sample code generated from IDL definitions.

I installed the ACE+TAO frameworks, and fiddled with things.¹

It looks like it's easier to go from the actual IDL.

The code to parse the IDL is included in the SDK, so maybe you can leverage that to generate some serialization code.

Sidenote: why Boost Serialize something that has IIOP serialization fully implemented for it? Could you consider Boost Serializing a binary buffer with the ACE serialization? If not, why not?


¹ actually compiling code: http://paste.ubuntu.com/12907686/

Thanks to @sehe, this seems to be working:

namespace boost { namespace serialization {

    template <typename Archive, typename T>
        inline void save(Archive& ar, const TAO::unbounded_value_sequence<T>& varSequence, unsigned int /*version*/)
        {
            size_t length = varSequence.length();
            ar & length
               & boost::serialization::make_array(varSequence.get_buffer(), varSequence.length());
        }

    template <typename Archive, typename T>
        void load(Archive& ar, TAO::unbounded_value_sequence<T>& varSequence, unsigned int /*version*/)
        {
            size_t length;
            ar & length;

            varSequence.length(length);
            ar & boost::serialization::make_array(varSequence.get_buffer(), varSequence.length());
        }

    template <typename Archive, typename T>
        inline void serialize(Archive& ar, TAO::unbounded_value_sequence<T>& varSequence, const unsigned int version)
        {
            split_free(ar, varSequence, version); 
        }

    template <class Archive>
        inline void serialize(Archive& ar, SequenceOfSomething& seq, unsigned int version)
        {
            ar & base_object<TAO::unbounded_value_sequence<Something>>(seq);
        }
} }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM