Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 95ff711 | 2015-02-10 19:11:33 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #ifndef NFD_TESTS_CORE_SIMPLE_NOTIFICATION_HPP |
| 27 | #define NFD_TESTS_CORE_SIMPLE_NOTIFICATION_HPP |
| 28 | |
| 29 | #include "common.hpp" |
| 30 | |
| 31 | #include "tests/test-common.hpp" |
| 32 | |
| 33 | namespace nfd { |
| 34 | namespace tests { |
| 35 | |
| 36 | class SimpleNotification |
| 37 | { |
| 38 | public: |
| 39 | SimpleNotification() |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | SimpleNotification(const std::string& message) |
| 44 | : m_message(message) |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | ~SimpleNotification() |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | Block |
| 53 | wireEncode() const |
| 54 | { |
| 55 | ndn::EncodingBuffer buffer; |
Alexander Afanasyev | dbe4f9f | 2015-06-28 11:23:49 -0700 | [diff] [blame] | 56 | prependStringBlock(buffer, 0x8888, m_message); |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 57 | return buffer.block(); |
| 58 | } |
| 59 | |
| 60 | void |
| 61 | wireDecode(const Block& block) |
| 62 | { |
| 63 | m_message.assign(reinterpret_cast<const char*>(block.value()), |
| 64 | block.value_size()); |
| 65 | |
| 66 | // error for testing |
| 67 | if (!m_message.empty() && m_message[0] == '\x07') |
| 68 | throw tlv::Error("0x07 error"); |
| 69 | } |
| 70 | |
| 71 | public: |
| 72 | const std::string& |
| 73 | getMessage() const |
| 74 | { |
| 75 | return m_message; |
| 76 | } |
| 77 | |
| 78 | void |
| 79 | setMessage(const std::string& message) |
| 80 | { |
| 81 | m_message = message; |
| 82 | } |
| 83 | |
| 84 | private: |
| 85 | std::string m_message; |
| 86 | }; |
| 87 | |
| 88 | } // namespace tests |
| 89 | } // namespace nfd |
| 90 | |
| 91 | #endif // NFD_TESTS_CORE_SIMPLE_NOTIFICATION_HPP |