#include <stdlib.h>
#include <cstring>
#include <vector>
-#include <iterator>
-#include <string.h>
#include <stdint.h>
/// \param len The length of the data in bytes.
InputBuffer(const void* data, size_t len) :
position_(0), data_(static_cast<const uint8_t*>(data)), len_(len) {}
-
- /// @brief Constructor from vector<uint8_t>
- ///
- /// It is caller's responsibility to ensure that the data is valid as long
- /// as the buffer exists.
- ///
- /// @param begin iterator to beginning of the vector
- /// @param end iterator to end of the vector
- InputBuffer(std::vector<uint8_t>::const_iterator begin,
- std::vector<uint8_t>::const_iterator end) :
- position_(0), data_(&(*begin)), len_(std::distance(begin, end)) {}
//@}
///
throwError("read beyond end of buffer");
}
- memcpy(data, &data_[position_], len);
+ std::memcpy(data, &data_[position_], len);
position_ += len;
}
//@}
if (buffer_ == NULL && allocated_ != 0) {
throw std::bad_alloc();
}
- memcpy(buffer_, other.buffer_, size_);
+ std::memcpy(buffer_, other.buffer_, size_);
}
/// \brief Destructor
buffer_ = newbuff;
size_ = other.size_;
allocated_ = other.allocated_;
- memcpy(buffer_, other.buffer_, size_);
+ std::memcpy(buffer_, other.buffer_, size_);
return (*this);
}
void writeData(const void *data, size_t len)
{
ensureAllocated(size_ + len);
- memcpy(buffer_ + size_, data, len);
+ std::memcpy(buffer_ + size_, data, len);
size_ += len;
}
//@}
EXPECT_EQ(0, memcmp(&vec[0], testdata+3, 2));
}
-TEST_F(BufferTest, inputBufferConstructorVector) {
- std::vector<uint8_t> vec(17);
- for (int i = 0; i < vec.size(); i++) {
- vec[i] = i;
- }
-
- InputBuffer buf(vec.begin(), vec.end());
-
- EXPECT_EQ(buf.getLength(), 17);
-
- std::vector<uint8_t> vec2;
- EXPECT_NO_THROW(buf.readVector(vec2, 17));
- EXPECT_TRUE(vec == vec2);
-}
-
}