Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014, 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 |
| 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; |
| 56 | prependByteArrayBlock(buffer, |
| 57 | 0x8888, |
| 58 | reinterpret_cast<const uint8_t*>(m_message.c_str()), |
| 59 | m_message.size()); |
| 60 | return buffer.block(); |
| 61 | } |
| 62 | |
| 63 | void |
| 64 | wireDecode(const Block& block) |
| 65 | { |
| 66 | m_message.assign(reinterpret_cast<const char*>(block.value()), |
| 67 | block.value_size()); |
| 68 | |
| 69 | // error for testing |
| 70 | if (!m_message.empty() && m_message[0] == '\x07') |
| 71 | throw tlv::Error("0x07 error"); |
| 72 | } |
| 73 | |
| 74 | public: |
| 75 | const std::string& |
| 76 | getMessage() const |
| 77 | { |
| 78 | return m_message; |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | setMessage(const std::string& message) |
| 83 | { |
| 84 | m_message = message; |
| 85 | } |
| 86 | |
| 87 | private: |
| 88 | std::string m_message; |
| 89 | }; |
| 90 | |
| 91 | } // namespace tests |
| 92 | } // namespace nfd |
| 93 | |
| 94 | #endif // NFD_TESTS_CORE_SIMPLE_NOTIFICATION_HPP |