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_BLOB_H |
| 14 | #define NDN_BLOB_H |
| 15 | |
| 16 | #include <vector> |
| 17 | #include <cstddef> |
Jeff Thompson | 4454bf7 | 2013-06-18 13:33:12 -0700 | [diff] [blame] | 18 | #include <boost/shared_ptr.hpp> |
Jeff Thompson | fa30664 | 2013-06-17 15:06:57 -0700 | [diff] [blame] | 19 | |
| 20 | namespace ndn { |
| 21 | |
Jeff Thompson | fa30664 | 2013-06-17 15:06:57 -0700 | [diff] [blame] | 22 | /** |
| 23 | * @brief Class representing a general-use binary blob |
| 24 | */ |
| 25 | class Blob : public std::vector<char> |
| 26 | { |
| 27 | public: |
| 28 | /** |
| 29 | * @brief Creates an empty blob |
| 30 | */ |
| 31 | Blob () |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | Blob (const void *buf, size_t length) |
| 36 | : std::vector<char> (reinterpret_cast<const char*> (buf), reinterpret_cast<const char*> (buf) + length) |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @brief Get pointer to the first byte of the binary blob |
| 42 | */ |
| 43 | inline char* |
| 44 | buf () |
| 45 | { |
| 46 | return &front (); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @brief Get const pointer to the first byte of the binary blob |
| 51 | */ |
| 52 | inline const char* |
| 53 | buf () const |
| 54 | { |
| 55 | return &front (); |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | } // ndn |
| 60 | |
| 61 | #endif // NDN_BLOB_H |