chrberger / libcluon Goto Github PK
View Code? Open in Web Editor NEWlibcluon is a small and efficient, single-file and header-only library written in modern C++ to power microservices.
License: Mozilla Public License 2.0
libcluon is a small and efficient, single-file and header-only library written in modern C++ to power microservices.
License: Mozilla Public License 2.0
Using gcc 9.3.0 on Ubuntu 20.04 (wsl2) and cluon-complete.hpp
from the latest release (v0.0.140). The compiler gives me the following warning related to a switch statement without default case in a lambda function:
[build] /build/cluon-complete.cpp: In lambda function:
[build] /build/cluon-complete.cpp:3692:5: warning: control reaches end of non-void function [-Wreturn-type]
[build] 3692 | };
[build] | ^
How to add a vector data type to an ODVD file?
The following warning, treated as error with -Werror flag), was provided by compiler g++ (version 6.4.0-r5) within Alpine 3.7 as docker image builder:
/opt/sources/src/cluon-complete.hpp: In member function 'virtual size_t peg::CharacterClass::parse(const char*, size_t, peg::SemanticValues&, peg::Context&, peg::any&) const': /opt/sources/src/cluon-complete.hpp:1754:39: error: 'cp' may be used uninitialized in this function [-Werror=maybe-uninitialized] if (range.first <= cp && cp <= range.second) { ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~ cc1plus: all warnings being treated as errors
I added a pair of parentheses after the declaration of cp in the line 1749, and the compiler was satisfied.
Description: When building from source, build fails at step "Building CXX object CMakeFiles/TestOD4Session.cpp-Runner.dir/testsuites/TestOD4Session.cpp.o"
Steps I performed:
cmake ../libcluon
make
Error Message : Pastebin
Time deltas in LibCluon are computed using cluon::data::TimeStamp now(), but it uses the Chrono-clock std::chrono::system_clock
which is not guaranteed not to be adjusted by the system at any time. This can cause problems in applications where the time delta is used to integrate speeds, just as an example. If the system decides to adjust the time backwards a few seconds, or an hour even as is common for daylight saving, then the delta can be a very large or even negative number that can throw off calculations.
For this reason, Chrono also offers a clock called std::chrono::steady_clock
that should be used whenever the time delta should be computed. The issue with this clock on the other hand is that it measures time since an unspecified epoch and not necessarily the Unix epoch.
I therefore suggest that the Time.hpp
is documented so that it warns users from using cluon::data::TimeStamp now()
in time-delta computations and that the alternative steady_clock
is used for that instead.
See also: #9
Trying to build it with current versions of cpp-peglib
etc. results in a spectacular failure.
libcluon_build_log.txt
Using the CMakeLists.txt from the libcluon folder I cant seem to find a way to disable the tests from being configured. This would make life easier when building from source instead of using the single-file, header-only distribution.
I cannot get it to compile using Visual Studio 2019 with C++17 standard enabled.
Compiler messages:
1>C:\dev\raspberry-console\socket\cluon.hpp(9806,76): error C2589: 'constant': illegal token on right side of '::'
1>C:\dev\raspberry-console\socket\cluon.hpp(9806,76): error C2062: type 'unknown-type' unexpected
1>C:\dev\raspberry-console\socket\cluon.hpp(9807,19): error C2181: illegal else without matching if
1>C:\dev\raspberry-console\socket\cluon.hpp(9793): error C2317: 'try' block starting on line '9793' has no catch handlers
1>C:\dev\raspberry-console\socket\cluon.hpp(9811,11): error C2181: illegal else without matching if
1>C:\dev\raspberry-console\socket\cluon.hpp(9812,23): error C2065: 'listOfMetaMessages': undeclared identifier
1>C:\dev\raspberry-console\socket\cluon.hpp(9814,7): error C2059: syntax error: 'catch'
1>C:\dev\raspberry-console\socket\cluon.hpp(9814,31): error C2143: syntax error: missing ';' before '{'
1>C:\dev\raspberry-console\socket\cluon.hpp(9814,31): error C2447: '{': missing function header (old-style formal list?)
1>C:\dev\raspberry-console\socket\cluon.hpp(9816,5): error C2059: syntax error: 'return'
1>C:\dev\raspberry-console\socket\cluon.hpp(9818,1): error C2059: syntax error: '}'
1>C:\dev\raspberry-console\socket\cluon.hpp(9818,1): error C2143: syntax error: missing ';' before '}'
1>C:\dev\raspberry-console\socket\cluon.hpp(9833,17): error C2143: syntax error: missing ';' before '{'
1>C:\dev\raspberry-console\socket\cluon.hpp(9833,17): error C2447: '{': missing function header (old-style formal list?)
1>C:\dev\raspberry-console\socket\cluon.hpp(13507,56): error C2589: 'constant': illegal token on right side of '::'
1>C:\dev\raspberry-console\socket\cluon.hpp(13507,8): error C2059: syntax error: '=='
1>C:\dev\raspberry-console\socket\cluon.hpp(13507,90): error C2143: syntax error: missing ';' before '{'
1>C:\dev\raspberry-console\socket\cluon.hpp(14140,56): error C2589: 'constant': illegal token on right side of '::'
1>C:\dev\raspberry-console\socket\cluon.hpp(14140,8): error C2059: syntax error: '=='
1>C:\dev\raspberry-console\socket\cluon.hpp(14140,90): error C2143: syntax error: missing ';' before '{'
1>C:\dev\raspberry-console\socket\cluon.hpp(14417,73): warning C4003: not enough arguments for function-like macro invocation 'max'
1>C:\dev\raspberry-console\socket\cluon.hpp(14417,73): error C2589: '(': illegal token on right side of '::'
1>C:\dev\raspberry-console\socket\cluon.hpp(14417,73): error C2062: type 'unknown-type' unexpected
1>C:\dev\raspberry-console\socket\cluon.hpp(14417,73): error C2059: syntax error: ')'
1>C:\dev\raspberry-console\socket\cluon.hpp(14418,73): warning C4003: not enough arguments for function-like macro invocation 'min'
1>C:\dev\raspberry-console\socket\cluon.hpp(14418,73): error C2589: '(': illegal token on right side of '::'
1>C:\dev\raspberry-console\socket\cluon.hpp(14418,73): error C2062: type 'unknown-type' unexpected
1>C:\dev\raspberry-console\socket\cluon.hpp(14418,73): error C2059: syntax error: ')'
1>C:\dev\raspberry-console\socket\cluon.hpp(14420,44): error C2589: '(': illegal token on right side of '::'
1>C:\dev\raspberry-console\socket\cluon.hpp(14420,44): error C2062: type 'unknown-type' unexpected
1>C:\dev\raspberry-console\socket\cluon.hpp(14420,44): error C2059: syntax error: ')'
1>C:\dev\raspberry-console\socket\cluon.hpp(14421,44): error C2589: '(': illegal token on right side of '::'
1>C:\dev\raspberry-console\socket\cluon.hpp(14421,44): error C2062: type 'unknown-type' unexpected
1>Generating Code...
1>C:\dev\raspberry-console\socket\cluon.hpp(14421,44): error C2059: syntax error: ')'
Looks like it fails while parsing MessageParserErrorCodes::NO_ERROR
for some reason.
Some code context:
9804 if (check4UniqueFieldNames(*ast, tmpPrefix, tmpMessageNames, tmpFieldNames, tmpNumericalMessageIdentifiers, tmpNumericalFieldIdentifiers)) {
9805 transform2MetaMessages(*ast, listOfMetaMessages);
9806 retVal = {listOfMetaMessages, MessageParserErrorCodes::NO_ERROR};
9807 } else {
9808 retVal = {listOfMetaMessages, MessageParserErrorCodes::DUPLICATE_IDENTIFIERS};
9809 }
Hi!
Thank you for open sourcing! Looking over unpacking, I was wondering if there's a way of outputting an enum alongside the generated C++ header for the message?
cluon::OD4Session od4(111,
[](cluon::data::Envelope &&envelope) noexcept {
if (envelope.dataType() == 2001) {
MyTestMessage1 receivedMsg = cluon::extractMessage<MyTestMessage1>(std::move(envelope));
PrimeChecker pc;
std::cout << receivedMsg.myValue() << " is"
<< (pc.isPrime(receivedMsg.myValue()) ? " " : " not ")
<< "a prime." << std::endl;
}
});
^Use case would be to swap out 2001 with an enum that's generated. Ideally this enum would also be present as generated proto enum (which I think is represented in the protobuf spec? If not, forgive my ignorance!). When I follow the docs the message id gets added as comments in the .proto file.
Cheers!
// Erik
It would be useful to be able to use this library in conjunction with https://pmem.io/pmdk/librpmem/ and RDMA to be able to have shared memory between systems.
Is there a form akin to RPC for such purposes?
I would hope that libcluon could update to use the latest v0.0.4 of the stringtoolbox library. It would simply be fantastic!
How can one efficiently transmit substantial volumes of data?
`using namespace std;
int main()
{
cout << "Hello CMake." << endl;
cluon::OD4Session od4{ 100 };
if (od4.isRunning()) {
// Let's wait for 5s before start sending our message.
using namespace std::chrono_literals;
std::this_thread::sleep_for(1s);
int count = 0;
std::vector<uint8_t> data;
data.resize(1024 *1024);
int index = 0;
for(auto& item : data)
{
item = index++ % 255;
}
// Let's create our message and set some values.
MyMessage1 msg;
msg.myNumber(count)
.data(std::string(data.begin(), data.end()))
.myText("Hello World!");
//// Finally, send the message.
while (true)
{
msg.myNumber(count++);
od4.send(msg);
}
}
return 0;
}
`
This project looks like a great idea.
I was trying to test, but I'm confused a bit.
It took me a minute but I eventually understood that I cannot define my protobuf messages using the actual google proto language. I must use the format that the cluon-msc
converter understands.
However, that seems pretty limited to scalar values, no arrays or "repeated" structures.
An example in proto language (very simple):
syntax = "proto2";
message SimpleMessage {
required int32 msg_id = 1;
optional string msg_string = 2;
}
message ComplexMessage {
required int32 complex_msg_id = 1;
repeated SimpleMessage messages = 2;
}
does not have a corresponding sintax in "odvd":
message SimpleMessage [id = 30000] {
uint32 msg_id [ id = 1 ];
string msg_payload [ default = "Hello World!", id = 2 ];
}
message ComplexMessage [id = 30001] {
uint32 complex_msg_id [ id = 1 ];
?
}
If I want something more complex like that, am I expected to extend the classes with definitions of things like you have in your cluon::data
namespace? I'm asking because I did not see much info on that other than looking at the code.
Thanks in advance.
The online compiler seems to be giving an error, see below. As far as I can tell wandbox.org is operational.
ReferenceError: twttr is not defined at https://wandbox.org/build/_shared/chunk-HWTQ5KW5.js:104:29713 at Gf (https://wandbox.org/build/_shared/chunk-2LKANNDY.js:9:6560) at L.unstable_runWithPriority (https://wandbox.org/build/_shared/chunk-2LKANNDY.js:1:4026) at rn (https://wandbox.org/build/_shared/chunk-2LKANNDY.js:5:38448) at Xe (https://wandbox.org/build/_shared/chunk-2LKANNDY.js:9:6029) at yi (https://wandbox.org/build/_shared/chunk-2LKANNDY.js:7:10750) at https://wandbox.org/build/_shared/chunk-2LKANNDY.js:5:38670 at L.unstable_runWithPriority (https://wandbox.org/build/_shared/chunk-2LKANNDY.js:1:4026) at rn (https://wandbox.org/build/_shared/chunk-2LKANNDY.js:5:38448) at Cs (https://wandbox.org/build/_shared/chunk-2LKANNDY.js:5:38616)
I found something in UDPReceiver class but it is behind a private variable.
I intend to add the libcluon recipe to the conan repsitory.
The version number is important for the conan recipe.
Currently, the url in the cluon-complete.hpp is not tagged by version.
Could you please add the cluon-complete.hpp to the release file like the nlohmann/json release?
https://github.com/nlohmann/json/releases/tag/v3.10.5
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.