Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Varun Patil | a24bd3e | 2020-11-24 10:08:33 +0530 | [diff] [blame] | 3 | * Copyright (c) 2020, Regents of the University of California |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 4 | * |
| 5 | * BSD license, See the LICENSE file for more information |
| 6 | * |
| 7 | * Author: Qiuhan Ding <qiuhanding@cs.ucla.edu> |
| 8 | */ |
| 9 | |
| 10 | #ifndef CHRONOCHAT_ENDORSE_INFO_HPP |
| 11 | #define CHRONOCHAT_ENDORSE_INFO_HPP |
| 12 | |
| 13 | #include "common.hpp" |
| 14 | #include "tlv.hpp" |
| 15 | #include <ndn-cxx/util/concepts.hpp> |
| 16 | #include <ndn-cxx/encoding/block.hpp> |
| 17 | #include <ndn-cxx/encoding/encoding-buffer.hpp> |
| 18 | |
| 19 | namespace chronochat { |
| 20 | |
| 21 | class EndorseInfo |
| 22 | { |
| 23 | |
| 24 | public: |
| 25 | |
| 26 | class Error : public std::runtime_error |
| 27 | { |
| 28 | public: |
| 29 | explicit |
| 30 | Error(const std::string& what) |
| 31 | : std::runtime_error(what) |
| 32 | { |
| 33 | } |
| 34 | }; |
| 35 | |
Varun Patil | a24bd3e | 2020-11-24 10:08:33 +0530 | [diff] [blame] | 36 | class Endorsement |
| 37 | { |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 38 | public: |
| 39 | std::string type; |
| 40 | std::string value; |
| 41 | std::string count; |
| 42 | }; |
| 43 | |
| 44 | public: |
| 45 | |
| 46 | EndorseInfo(); |
| 47 | |
| 48 | explicit |
| 49 | EndorseInfo(const Block& endorseWire); |
| 50 | |
| 51 | const Block& |
| 52 | wireEncode() const; |
| 53 | |
| 54 | void |
| 55 | wireDecode(const Block& endorseWire); |
| 56 | |
| 57 | const std::vector<Endorsement>& |
| 58 | getEndorsements() const; |
| 59 | |
| 60 | void |
| 61 | addEndorsement(const std::string& type, const std::string& value, const std::string& count); |
| 62 | |
| 63 | private: |
Varun Patil | 3d85090 | 2020-11-23 12:19:14 +0530 | [diff] [blame] | 64 | template<ndn::encoding::Tag T> |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 65 | size_t |
| 66 | wireEncode(ndn::EncodingImpl<T>& block) const; |
| 67 | |
| 68 | private: |
| 69 | mutable Block m_wire; |
| 70 | std::vector<Endorsement> m_endorsements; |
| 71 | }; |
| 72 | |
| 73 | inline const std::vector<EndorseInfo::Endorsement>& |
| 74 | EndorseInfo::getEndorsements() const |
| 75 | { |
| 76 | return m_endorsements; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | } // namespace chronochat |
| 81 | |
Varun Patil | a24bd3e | 2020-11-24 10:08:33 +0530 | [diff] [blame] | 82 | #endif // CHRONOCHAT_ENDORSE_INFO_HPP |