blob: ce0d667bd94022b0874253bcb7242a170507952c [file] [log] [blame]
Jeff Thompsonfa306642013-06-17 15:06:57 -07001/* -*- 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 Thompson4454bf72013-06-18 13:33:12 -070018#include <boost/shared_ptr.hpp>
Jeff Thompsonfa306642013-06-17 15:06:57 -070019
20namespace ndn {
21
Jeff Thompson4454bf72013-06-18 13:33:12 -070022class Blob;
23typedef boost::shared_ptr<Blob> BlobPtr;
24typedef boost::shared_ptr<const Blob> ConstBlobPtr;
25
Jeff Thompsonfa306642013-06-17 15:06:57 -070026/**
27 * @brief Class representing a general-use binary blob
28 */
29class Blob : public std::vector<char>
30{
31public:
32 /**
33 * @brief Creates an empty blob
34 */
35 Blob ()
36 {
37 }
38
39 Blob (const void *buf, size_t length)
40 : std::vector<char> (reinterpret_cast<const char*> (buf), reinterpret_cast<const char*> (buf) + length)
41 {
42 }
43
44 /**
45 * @brief Get pointer to the first byte of the binary blob
46 */
47 inline char*
48 buf ()
49 {
50 return &front ();
51 }
52
53 /**
54 * @brief Get const pointer to the first byte of the binary blob
55 */
56 inline const char*
57 buf () const
58 {
59 return &front ();
60 }
61};
62
63} // ndn
64
65#endif // NDN_BLOB_H