add tests

This commit is contained in:
2024-10-16 12:35:45 +02:00
parent fc405eeba1
commit a0fcd8b985
14 changed files with 515 additions and 67 deletions

View File

@@ -10,8 +10,8 @@
#include <cstdint>
#include <cstring>
#include <string>
#include <vector>
#include <td/common/VarInt.h>
#include <vector>
namespace td {
@@ -76,11 +76,23 @@ class DataBuffer {
/**
* \brief Append a vector to the buffer by first writing the size
* \param data The buffer to append
* \param data The vector to append
*/
template <typename T>
DataBuffer& operator<<(const std::vector<T>& data) {
*this << VarInt {data.size()};
*this << VarInt{data.size()};
for (const auto& element : data) {
*this << element;
}
return *this;
}
/**
* \brief Append an array to the buffer by first writing the size
* \param data The buffer to append
*/
template <typename T, std::size_t Size>
DataBuffer& operator<<(const std::array<T, Size>& data) {
for (const auto& element : data) {
*this << element;
}
@@ -112,7 +124,7 @@ class DataBuffer {
DataBuffer& operator>>(std::string& str);
/**
* \brief Read a vector (size + data) from the buffer
* \brief Read a vector (size + data) from the buffer
* \pre The vector is assumed to be empty
*/
template <typename T>
@@ -127,6 +139,19 @@ class DataBuffer {
return *this;
}
/**
* \brief Read an array from the buffer
*/
template <std::size_t Size, typename T>
DataBuffer& operator>>(std::array<T, Size>& data) {
for (std::size_t i = 0; i < Size; i++) {
T newElement;
*this >> newElement;
data[i] = newElement;
}
return *this;
}
/**
* \brief Write some data to the buffer
* \param buffer The buffer to write

View File

@@ -2,7 +2,7 @@
/**
* \file VarInt.h
* \brief File containing the blitz::VarInt class
* \brief File containing the td::VarInt class
*/
#include <cstddef>