#include
#include
#include
static constexpr unsigned int SIZE_OF_HEADER = 5;
typedef std::vector buffer;
void addSizeToVector(std::vector& vec, uint32_t size);
int main()
{
buffer result(SIZE_OF_HEADER);
// Insert the code & size of json at the beginning of the buffer
result.push_back(static_cast(2));
addSizeToVector(result, 770); // The size for this demonstration
std::cout > 8) & 0xFF));
vec.push_back(static_cast(size & 0xFF)); // Least significant byte
}
< /code>
Я пытаюсь заполнить буфер с помощью заголовка, который мне нужен для моего сообщения, но он не успешен и просто дает мне заголовок Zeros
ожидаемое значение: < /p>
< /p>
Подробнее здесь: [url]https://stackoverflow.com/questions/79596022/adding-bytes-to-a-vector-buffer-adds-only-zeros[/url]
// Insert the code & size of json at the beginning of the buffer result.push_back(static_cast(2)); addSizeToVector(result, 770); // The size for this demonstration
std::cout > 8) & 0xFF)); vec.push_back(static_cast(size & 0xFF)); // Least significant byte } < /code> Я пытаюсь заполнить буфер с помощью заголовка, который мне нужен для моего сообщения, но он не успешен и просто дает мне заголовок Zeros