#pragma once /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ /** @file */ /** @copyright 2021 MPLv2 */ #include #include /** * @brief This is the main namespace for all whisper-com related datatypes and classed. */ namespace Whisper { /** * @brief All available Message types. * * Message Types identify the real type of the payload of the message */ enum class MessageType : std::uint8_t { /// no message type set or identified NONE, /// the message is a Announcement Message Version 1 ANNOUNCEMENT_V1 }; // enum class MessageType class Message : public Whisper::Transmittable { private: std::uint64_t dstID_; std::uint64_t srcID_; std::uint64_t messageID_; std::uint64_t replyID_; Whisper::MessageType type_; std::shared_ptr payload_; std::shared_ptr> rawPayload_; /** * @brief Method generates a random uint64 value > 0 * * Please be aware that this method will never return zero, as * zero indicates that the id has never been set. * * @return std::uint64_t > 0 */ std::uint64_t randomID_(); void decode(std::shared_ptr> data); public: Message() : dstID_(0), srcID_(0), messageID_(randomID_()), replyID_(0), type_(Whisper::MessageType::NONE), payload_(nullptr), rawPayload_(nullptr), Transmittable() {} Message(std::shared_ptr> data) : Message() {decode(data);} std::uint64_t size(); Whisper::MessageType type() const { return type_;} void type(Whisper::MessageType type) {type_=type;} std::uint64_t id() const {return messageID_;} std::uint64_t replyId() const { return replyID_;} std::uint64_t src() const {return srcID_;} std::uint64_t dst() const {return dstID_;} std::shared_ptr> encode(); std::shared_ptr getPayload(); }; // Message }; // namespace Whisper