26 #include "../common.hpp"
27 #include "../c/util/blob-types.h"
28 #include "../lite/util/blob-lite.hpp"
42 class Blob :
public ptr_lib::shared_ptr<const std::vector<uint8_t> > {
57 Blob(
const uint8_t* value,
size_t valueLength)
58 :
ptr_lib::shared_ptr<const
std::vector<uint8_t> >
59 (value ? new
std::vector<uint8_t>(value, value + valueLength) : 0)
69 Blob(
const std::vector<uint8_t> &value)
70 :
ptr_lib::shared_ptr<const
std::vector<uint8_t> >(new
std::vector<uint8_t>(value))
80 :
ptr_lib::shared_ptr<const
std::vector<uint8_t> >
82 new
std::vector<uint8_t>(blobStruct.value, blobStruct.value + blobStruct.length)
93 :
ptr_lib::shared_ptr<const
std::vector<uint8_t> >
95 : new
std::vector<uint8_t>(blobLite.
buf(), blobLite.
buf() + blobLite.
size()))
104 :
ptr_lib::shared_ptr<const
std::vector<uint8_t> >(blob)
116 Blob(
const ptr_lib::shared_ptr<std::vector<uint8_t> > &value,
bool copy)
117 :
ptr_lib::shared_ptr<const
std::vector<uint8_t> >
118 ((const
ptr_lib::shared_ptr<const
std::vector<uint8_t> > &)value)
121 this->reset(
new std::vector<uint8_t>(*value));
123 Blob(
const ptr_lib::shared_ptr<
const std::vector<uint8_t> > &value,
bool copy)
124 :
ptr_lib::shared_ptr<const
std::vector<uint8_t> >(value)
127 this->reset(
new std::vector<uint8_t>(*value));
134 DEPRECATED_IN_NDN_CPP
Blob(
const ptr_lib::shared_ptr<std::vector<uint8_t> > &value)
135 :
ptr_lib::shared_ptr<const
std::vector<uint8_t> >((const
ptr_lib::shared_ptr<const
std::vector<uint8_t> > &)value)
138 DEPRECATED_IN_NDN_CPP
Blob(
const ptr_lib::shared_ptr<
const std::vector<uint8_t> > &value)
139 :
ptr_lib::shared_ptr<const
std::vector<uint8_t> >(value)
150 return (*this)->size();
162 return &(*this)->front();
190 return (*
this) ? std::string((
const char*)(&(*this)->front()), (*this)->size())
209 return (**
this) == (*other);
220 blobStruct.length =
size();
221 blobStruct.value = (
size() > 0 ?
buf() : 0);
227 return BlobLite(&(*this)->front(), (*this)->size());
234 operator << (std::ostream& os,
const Blob& blob)
236 for (
size_t i = 0; i < blob.size(); ++i)
DEPRECATED_IN_NDN_CPP Blob(const ptr_lib::shared_ptr< std::vector< uint8_t > > &value)
Create a new Blob to point to an existing byte array.
Definition: blob.hpp:134
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
Blob(const BlobLite &blobLite)
Create a new Blob with an immutable copy of the array in blobLite.
Definition: blob.hpp:92
Copyright (C) 2015-2016 Regents of the University of California.
bool isNull() const
Check if the array pointer is null.
Definition: blob.hpp:172
Blob(const Blob &blob)
Create a new Blob and take another pointer to the given blob's buffer.
Definition: blob.hpp:103
Blob(const struct ndn_Blob &blobStruct)
Create a new Blob with an immutable copy of the array in the given Blob struct.
Definition: blob.hpp:79
A Blob holds a pointer to an immutable byte array implemented as const std::vector.
Definition: blob.hpp:42
const uint8_t * buf() const
Return a const pointer to the first byte of the immutable byte array, or 0 if the pointer is null...
Definition: blob.hpp:159
size_t size() const
Return the length of the immutable byte array.
Definition: blob.hpp:147
std::string toRawStr() const
Return the bytes of the byte array as a raw str of the same length.
Definition: blob.hpp:188
Blob()
Create a new Blob with a null pointer.
Definition: blob.hpp:47
A BlobLite holds a pointer to an immutable pre-allocated buffer and its length This is like a JavaScr...
Definition: blob-lite.hpp:37
Copyright (C) 2015-2016 Regents of the University of California.
Definition: blob-types.h:33
std::string toHex(const uint8_t *array, size_t arrayLength)
Return the hex representation of the bytes in array.
Definition: common.cpp:30
Blob(const uint8_t *value, size_t valueLength)
Create a new Blob with an immutable copy of the given array.
Definition: blob.hpp:57
Blob(const ptr_lib::shared_ptr< std::vector< uint8_t > > &value, bool copy)
Create a new Blob to point to an existing byte array.
Definition: blob.hpp:116
std::string toHex() const
Return the hex representation of the bytes in array.
Definition: blob.hpp:180
bool equals(const Blob &other) const
Check if the value of this Blob equals the other blob.
Definition: blob.hpp:201
Blob(const std::vector< uint8_t > &value)
Create a new Blob with an immutable copy of the array in the given vector.
Definition: blob.hpp:69