22 #ifndef NDN_DYNAMIC_UCHAR_VECTOR_HPP
23 #define NDN_DYNAMIC_UCHAR_VECTOR_HPP
27 #include <ndn-cpp/common.hpp>
28 #include <ndn-cpp/util/blob.hpp>
29 #include "../c/util/dynamic-uint8-array.h"
55 if ((error = ndn_DynamicUInt8Array_ensureLength(
this, length)))
56 throw std::runtime_error(ndn_getErrorString(error));
68 copy(
const uint8_t *value,
size_t valueLength,
size_t offset)
71 if ((error = ndn_DynamicUInt8Array_copy(
this, value, valueLength, offset)))
72 throw std::runtime_error(ndn_getErrorString(error));
74 return offset + valueLength;
85 copy(
const std::vector<uint8_t>& value,
size_t offset)
87 return copy(&value[0], value.size(), offset);
100 if ((error = ndn_DynamicUInt8Array_ensureLengthFromBack(
this, length)))
101 throw std::runtime_error(ndn_getErrorString(error));
114 copyFromBack(
const uint8_t *value,
size_t valueLength,
size_t offsetFromBack)
117 if ((error = ndn_DynamicUInt8Array_copyFromBack
118 (
this, value, valueLength, offsetFromBack)))
119 throw std::runtime_error(ndn_getErrorString(error));
126 ptr_lib::shared_ptr<std::vector<uint8_t> >&
127 get() {
return vector_; }
138 vector_->resize(size);
139 Blob result(vector_,
false);
145 operator [] (
size_t i) {
return (*vector_)[i]; }
148 operator [] (
size_t i)
const {
return (*vector_)[i]; }
161 ptr_lib::shared_ptr<std::vector<uint8_t> > vector_;
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
Blob finish(size_t size)
Resize the allocated vector to the given size, transfer the bytes to a Blob and return the Blob...
Definition: dynamic-uint8-vector.hpp:136
size_t copy(const std::vector< uint8_t > &value, size_t offset)
Copy value into the vector at offset, using ensureLength to make sure the vector has enough size...
Definition: dynamic-uint8-vector.hpp:85
A Blob holds a pointer to an immutable byte array implemented as const std::vector.
Definition: blob.hpp:42
void ensureLengthFromBack(size_t length)
Ensure that the vector size is greater than or equal to length.
Definition: dynamic-uint8-vector.hpp:97
A struct ndn_DynamicUInt8Array holds a pointer to an allocated array, the length of the allocated arr...
Definition: dynamic-uint8-array-types.h:40
size_t length
the length of the allocated array buffer
Definition: dynamic-uint8-array-types.h:42
DynamicUInt8Vector(size_t initialLength)
Create a new DynamicUInt8Vector with an initial length.
Definition: dynamic-uint8-vector.cpp:28
size_t copy(const uint8_t *value, size_t valueLength, size_t offset)
Copy value into the vector at offset, using ensureLength to make sure the vector has enough size...
Definition: dynamic-uint8-vector.hpp:68
void ensureLength(size_t length)
Ensure that the vector size is greater than or equal to length.
Definition: dynamic-uint8-vector.hpp:52
void copyFromBack(const uint8_t *value, size_t valueLength, size_t offsetFromBack)
First call ensureLengthFromBack to make sure the vector has offsetFromBack bytes. ...
Definition: dynamic-uint8-vector.hpp:114
A DynamicUInt8Vector extends ndn_DynamicUInt8Array to hold a shared_ptr > for use wit...
Definition: dynamic-uint8-vector.hpp:37
uint8_t * array
the allocated array buffer
Definition: dynamic-uint8-array-types.h:41