Jeff Thompson | fa30664 | 2013-06-17 15:06:57 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013, Regents of the University of California |
| 4 | * Alexander Afanasyev |
| 5 | * Zhenkai Zhu |
| 6 | * |
| 7 | * BSD license, See the LICENSE file for more information |
| 8 | * |
| 9 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 10 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 11 | */ |
| 12 | |
| 13 | #ifndef NDN_SIGNED_BLOB_H |
| 14 | #define NDN_SIGNED_BLOB_H |
| 15 | |
| 16 | #include "blob.h" |
| 17 | |
| 18 | namespace ndn { |
| 19 | |
| 20 | /** |
| 21 | * @brief Class representing a blob, which has a signed portion (e.g., bytes of DATA packet) |
| 22 | */ |
| 23 | class SignedBlob : public Blob |
| 24 | { |
| 25 | public: |
| 26 | /** |
| 27 | * @brief Set signed portion of the blob |
| 28 | * @param offset An offset from the beginning of the blob |
| 29 | * @param size Size of the signed portion of the blob |
| 30 | */ |
| 31 | inline void |
| 32 | setSignedPortion (size_t offset, size_t size); |
| 33 | |
| 34 | /** |
| 35 | * @brief Get begin iterator to a signed portion of the blob |
| 36 | */ |
| 37 | inline const_iterator |
| 38 | signed_begin () const; |
| 39 | |
| 40 | /** |
| 41 | * @brief Get end iterator of a signed portion of the blob |
| 42 | */ |
| 43 | inline const_iterator |
| 44 | signed_end () const; |
| 45 | |
| 46 | /** |
| 47 | * @brief Get pointer to a first byte of the signed blob |
| 48 | */ |
| 49 | inline const char* |
| 50 | signed_buf () const; |
| 51 | |
| 52 | /** |
| 53 | * @brief Get size of the signed blob |
| 54 | */ |
| 55 | inline size_t |
| 56 | signed_size () const; |
| 57 | |
| 58 | private: |
| 59 | const_iterator m_signedBegin; |
| 60 | const_iterator m_signedEnd; |
| 61 | }; |
| 62 | |
| 63 | |
| 64 | inline void |
| 65 | SignedBlob::setSignedPortion (size_t offset, size_t size) |
| 66 | { |
| 67 | m_signedBegin = begin () + offset; |
| 68 | m_signedEnd = begin () + offset + size; |
| 69 | } |
| 70 | |
| 71 | inline SignedBlob::const_iterator |
| 72 | SignedBlob::signed_begin () const |
| 73 | { |
| 74 | return m_signedBegin; |
| 75 | } |
| 76 | |
| 77 | inline SignedBlob::const_iterator |
| 78 | SignedBlob::signed_end () const |
| 79 | { |
| 80 | return m_signedEnd; |
| 81 | } |
| 82 | |
| 83 | inline const char* |
| 84 | SignedBlob::signed_buf () const |
| 85 | { |
| 86 | return &*m_signedBegin; |
| 87 | } |
| 88 | |
| 89 | inline size_t |
| 90 | SignedBlob::signed_size () const |
| 91 | { |
| 92 | return m_signedEnd - m_signedBegin; |
| 93 | } |
| 94 | |
Jeff Thompson | fa30664 | 2013-06-17 15:06:57 -0700 | [diff] [blame] | 95 | } // ndn |
| 96 | |
| 97 | #endif // NDN_SIGNED_BLOB_H |