CasePacker.h 778 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#pragma once
#include "ros_bridge/include/MessageBaseClass.h"

#include <memory>
#include "rapidjson/include/rapidjson/document.h"

namespace ROSBridge {

class CasePacker
{
    typedef rapidjson::Document JsonDoc;
    typedef std::unique_ptr<JsonDoc> UniqueJsonPtr;
public:
    CasePacker();

    struct MessageTag {
       char *topic;
       char *messagType;
    };
    typedef MessageTag Tag;


    template<class T>
    void packAndSend(const T &msg, const char *topic);

    const Tag &showTag();

    template<class T>
    void unpack(T &msg);

protected:
    void _addTag(JsonDoc &doc, const char *topic, const char *messageType);
    void _removeTag(JsonDoc &doc);

    static const char* topicKey;
    static const char* messageTypeKey;

private:
    Tag _tag;
};
}