Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
ligier Namespace Reference

Functions

std::size_t prepare_tag (char *buffer, std::size_t max_size, std::string const &tag)
 
std::size_t read_data_size (char const *const buffer)
 

Detailed Description

Author
cpellegrino

Function Documentation

◆ prepare_tag()

std::size_t ligier::prepare_tag ( char * buffer,
std::size_t max_size,
std::string const & tag )

Definition at line 16 of file ligier_helper.cpp.

20 {
21 static std::string const header = "_Subscri";
22 static std::string const mode = " w ";
23 static std::string const trailer = "_Always";
24
25 uint32_t const tagsize = ntohl(3 + tag.size());
26
27 std::size_t const total_size
28 = header.size()
29 + sizeof(tagsize)
30 + 4
31 + mode.size()
32 + tag.size()
33 + trailer.size()
34 + 9;
35
36 if (total_size > max_size) {
37 throw std::runtime_error("buffer too small");
38 }
39
40 std::memset(buffer, '\0', total_size);
41
42 std::memcpy(buffer, header.c_str(), header.size());
43 buffer += header.size();
44 std::memcpy(buffer, &tagsize, sizeof(tagsize));
45 buffer += sizeof(tagsize);
46 buffer += 4;
47 std::memcpy(buffer, mode.c_str(), mode.size());
48 buffer += mode.size();
49 std::memcpy(buffer, tag.c_str(), tag.size());
50 buffer += tag.size();
51 std::memcpy(buffer, trailer.c_str(), trailer.size());
52
53 return total_size;
54}

◆ read_data_size()

std::size_t ligier::read_data_size ( char const *const buffer)

Definition at line 56 of file ligier_helper.cpp.

57{
58 uint32_t const& message_size = *static_cast<uint32_t const* const>(
59 static_cast<void const* const>(buffer + 8)
60 );
61
62 return ntohl(message_size);
63}