Skip to content

Commit

Permalink
removed serializable since I won't write serialization
Browse files Browse the repository at this point in the history
Took 12 minutes
  • Loading branch information
kagurazaka-ayano committed Jan 31, 2024
1 parent c78f049 commit f84089a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
3 changes: 3 additions & 0 deletions include/KawaiiMQ/Consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace KawaiiMQ {

explicit Consumer(std::vector<Topic> topics);

explicit Consumer(const std::string& name);

/**
* subscribe a topic
* @param topic given topic
Expand Down Expand Up @@ -54,6 +56,7 @@ namespace KawaiiMQ {

private:
std::mutex mtx;
std::string name;
std::vector<Topic> subscribed;
};

Expand Down
21 changes: 0 additions & 21 deletions include/KawaiiMQ/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,13 @@

namespace KawaiiMQ {

class ISerializable {
public:
virtual ~ISerializable() = default;

/**
* serialize the object
* @return serialized string
*/
virtual std::string serialize() const = 0;

/**
* deserialize the object
* @param data serialized data
*/
virtual void deserialize(const std::string &data) = 0;
};

class MessageData {
public:
MessageData() = default;
virtual ~MessageData() = default;
};

template<typename T>
requires std::is_base_of_v<ISerializable, T> || std::is_fundamental_v<T>
class Message : public MessageData {
public:
explicit Message(T content) : content(std::move(content)) {}
Expand All @@ -47,15 +29,13 @@ namespace KawaiiMQ {
}

template<typename U>
requires std::is_base_of_v<ISerializable, U> || std::is_fundamental_v<U>
friend U getMessage(std::shared_ptr<MessageData> in);

private:
T content;
};

template<typename T>
requires std::is_base_of_v<ISerializable, T> || std::is_fundamental_v<T>
T getMessage(std::shared_ptr<MessageData> in) {
std::shared_ptr<Message<T>> tmp = std::dynamic_pointer_cast<Message<T>>(in);
if (tmp != nullptr) {
Expand All @@ -66,7 +46,6 @@ namespace KawaiiMQ {
}

template<typename T>
requires std::is_base_of_v<ISerializable, T> || std::is_fundamental_v<T>
std::shared_ptr<Message<T>> makeMessage(T content) {
auto msg = std::make_shared<Message<T>>(content);
return msg;
Expand Down
7 changes: 7 additions & 0 deletions include/KawaiiMQ/Producer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace KawaiiMQ {

class Producer {
public:
explicit Producer(const std::string &name);

/**
* subscribe to a topic
* @param topic topic you want to subscribe
Expand Down Expand Up @@ -69,9 +71,14 @@ namespace KawaiiMQ {
}
}
}

std::string getName() const {
return name;
}
private:
std::vector<Topic> subscribed;
std::mutex mtx;
std::string name;
};
}

Expand Down
4 changes: 4 additions & 0 deletions src/Consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ namespace KawaiiMQ {
return ret;
}

Consumer::Consumer(const std::string &name): name(name) {

}

}
4 changes: 4 additions & 0 deletions src/Producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ namespace KawaiiMQ {
}
subscribed.erase(std::remove(subscribed.begin(), subscribed.end(), topic));
}

Producer::Producer(const std::string &name) {
this->name = name;
}
}

0 comments on commit f84089a

Please sign in to comment.