CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
test
test/Buffer.cpp
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#include "
Buffer.h
"
8
#include <climits>
9
#include <random>
10
11
namespace
util
{
12
namespace
buffer
{
13
14
shared_buffer
make_random
(
size_t
size) {
15
if
(size == 0u)
16
return
make_empty();
17
// independent_bits_engine requires an unsigned result type wider than
18
// char ([rand.req.genl]/1.6); MSVC enforces this with a static_assert.
19
using
random_bytes_engine = std::independent_bits_engine<
20
std::random_device,
21
CHAR_BIT,
22
unsigned
short
>;
23
random_bytes_engine rbe;
24
auto
buffer
= make_empty(size);
25
std::generate(
buffer
->begin(),
buffer
->end(), [&rbe]() {
26
return static_cast<unsigned char>(rbe());
27
});
28
return
buffer
;
29
}
30
31
std::string
to_hex_string
(
const
Buffer
&buf,
size_t
length) {
32
length = std::min(
static_cast<
size_t
>
(buf.
size
()), length);
33
auto
buffer
= std::make_unique<char[]>(2u * length + 1u);
34
for
(
auto
i = 0u; i < length; ++i)
35
sprintf(&
buffer
[2u * i],
"%02x"
, buf.
data
()[i]);
36
if
(length < buf.
size
())
37
return
std::string(
buffer
.get()) + std::string(
"..."
);
38
return
std::string(
buffer
.get());
39
}
40
41
}
// namespace buffer
42
}
// namespace util
carla::Buffer
A piece of raw data.
Definition
carla/Buffer.h:42
carla::Buffer::data
const value_type * data() const noexcept
Direct access to the allocated memory or nullptr if no memory is allocated.
Definition
carla/Buffer.h:156
carla::Buffer::size
size_type size() const noexcept
Definition
carla/Buffer.h:197
util::buffer
Definition
test/Buffer.cpp:12
util::buffer::shared_buffer
std::shared_ptr< Buffer > shared_buffer
Definition
test/Buffer.h:21
util::buffer::to_hex_string
std::string to_hex_string(const Buffer &buf, size_t length)
Definition
test/Buffer.cpp:31
util::buffer::make_random
shared_buffer make_random(size_t size)
Definition
test/Buffer.cpp:14
util
Definition
test/Buffer.cpp:11
Buffer.h
Generated by
1.18.0