macchina-io / macchina.io

macchina.io EDGE is a powerful C++ and JavaScript SDK for edge devices, multi-service IoT gateways and connected embedded systems.
https://macchina.io
GNU General Public License v3.0
512 stars 152 forks source link

Serialize/Deserialize Document object #100

Closed zaleksa closed 2 years ago

zaleksa commented 3 years ago

As i understood, only classes and structures can be serialized. Whether complex data types contained in structure can be serialized?

I have custom class with '@ remote' directive, so its public methods are reachable from other bundles. Is it possible to have public method which will return Poco::XML::Document object as return type?

I tried to place Poco::XML::Document variable inside structure which has '@ serialize' directive, run remoteNG generator, but when I try to compile bundle, I get error "DocumentSerializer.h: No such file or directory". I understand that it must be DocumentSerializer and DocumentDeserializer helper classes, but I don't know how to generate it.

Do I have to write TypeSerializer for Document type, and where and how should I do it?

Inside MyBundle I have:

//@ serialize struct DocumentValue { DocumentValue(): _pDocument(NULL) { }

Poco::AutoPtr<Poco::XML::Document> _pDocument;

};

Helper class DocumentValueSerializer contains:

include "IoT/MyBundle/DocumentDeserializer.h"

include "IoT/MyBundle/DocumentSerializer.h"

include "IoT/MyBundle/MbusPollControl.h"

include "Poco/RemotingNG/TypeSerializer.h"

namespace Poco { namespace RemotingNG {

template <> class TypeSerializer { public: static void serialize(const std::string& name, const MyBundle::DocumentValue& value, Serializer& ser) { ser.serializeStructBegin(name); serializeImpl(value, ser); ser.serializeStructEnd(name); }

static void serializeImpl(const MyBundle::DocumentValue& value, Serializer& ser)
{
    remoting__staticInitBegin(REMOTING__NAMES);
    static const std::string REMOTING__NAMES[] = {"pDocument",""};
    remoting__staticInitEnd(REMOTING__NAMES);
    TypeSerializer<Poco::AutoPtr < Poco::XML::Document > >::serialize(REMOTING__NAMES[0], value._pDocument, ser);
}

};

} // namespace RemotingNG } // namespace Poco

Any example would be of great help to me.

Thanks in advance Aleksandar