C++ equivalent to SerializeWithLengthPrefix - protocol-buffers

I built a communication library using Protocol Buffers (protobuf-net) using Sockets (TcpListener and TcpClient) and it is working fine, but now a co-worker needs to write a library to communicate with my software using C++.
Turns out that I'm using the Serializer.NonGeneric.SerializeWithLengthPrefix and Serializer.NonGeneric.TryDeserializeWithLengthPrefix.
Are there equivalent functions in the protobuf C++ libraries? If not, anyone knows how to implement it, or have it implemented to share?

I'm not hugely familiar with the C++ API; but the length prefix itself is pretty simple if you write the data to a buffer first, especially if you use the fixed-width 32-bit encoding (rather than base-128 variable-length). See also this thread on the google-groups forum.

Related

Using boost.asio on esp32 (lwip)

I am trying to port code using boost.asio onto the esp32 (esp-idf) which in turn uses lwip, mbedtls and FreeRTOS using preemptive multitasking.
The esp-idf exposes a Linux/Posix-like interface and most stuff compiles out of the box. Lwip exposes a standard BSD socket interface including select() and blocking and non-blocking sockets etc, but it does not have poll().
So in principle I would think that everything should be there to make boost.asio happy. What I find is that boost.asio (e.g. socket_ops.ipp) contains code variants for many OSes, and it is clear to me that esp32 is not a supported platform.
My question is: What is currently the best alignment of the BOOST_ASIO_* #defines when targeting the esp32?
(I am currently drilling into this and I am modifying both boost.asio and the esp-idf to fit together, but I already made unnecessary changes, thus asking this question.)

How to generate executable across platforms

in case i have a source code and an api to generate windows executable version, is there any possibility or any easy approach to convert it into something that can be executed across Linux /mac or Solaris platforms?
If your code is in a .NET language, there are online and offline translators that can convert the code to Java.
This is just language translation, and doesn't convert the API calls, but it would be a first step in the process.
Another way to handle the problem would be to choose a cloud-based web service or bridge solution. If you have a significant amount of program logic, exposing APIs in this way would allow you to maintain much of the code in its existing language, while making it invocable on other platforms.

Is it possible to create an application WITHOUT a framework?

I was just thinking. C# has Winforms/WPF, Java has Swing and other frameworks, C++ has QT and so on; is it possible to create an application without using a Framework?
Putting aside the practicality of it, I'm just curious. How would one create an application that Just Works(tm) without needing external frameworks?
Two options come to mind:
Classical Win32 applications written in C. I don't know if standard Windows SDK API also counts as an "external framework" in your book, but that's as low as it gets.
DirectX/OpenGL games written from scratch with your own homebrew framework (not external, right?) There you get to do all the drawing yourself - although again, you use a pretty big library of primitive drawing functions.
If you want even less "framework", you'll have to code your own OS and drivers. :P
C# needs .NET Framework, not WinForms (which is an optional library used by some application). The same with Java.
Unmanaged (native) applications usually use some runtime library - the library of common functions. You can write a native application without any library - the compiler lets you do this, but you will need to (re)write lots of common functions, eg. for string manipulation etc..
Firstly, what is a framework?
Really a framework is just a bunch of code that is provided to you. You could, at least in theory, write the same code yourself. In that case you wouldn't be using a framework.
Your application can only do what the operating system allows it to do. Your program cannot directly manipulate the graphics card for example. So you have to use the APIs of your operating system in order to do anything.
So you are going to be calling into other code. (unless you write your own operating system). You will also being using another framework or api to get stuff done.
Yes. How: in the way that the frameworks you mentioned are implemented.
From a Windows point of view, you would register your window with Windows, then listen to window messages and react as required. Everything would be up to you - from drawing the window to building controls.

What modbus library should I use for modbus protocol for GCC

We are building a product, which requires modbus communication (both rs-485 and TCP/IP). The code has to run on an embedded device which has Linux running on it. We have following criteria for the selecting the library that we would be using.
It has to be opensource, since we are opensource geeks.
We would give this product to our users and what their application would be we are not aware, hence it has to complete implementation of the modbus protocol.
Wide user base: What we believe is that greater the users of the code, more the stability of the code.
I came across two such libraries:
http://www.freemodbus.org
and
libmodbus
Are there any more modbus libraries. Please suggest with pros and cons
I'd suggest libmodbus, it works well and is cross platform.
http://www.libmodbus.org
I am just starting to explore these options as well. My priority is on ease of use which has led me to RModBus since it was the only one that I was able to get immediate results with. However, there is also a Python library, Pymodbus, that appears to be quite complete in implementation.
I'm sorry, I just figured out that GCC is a compiler; my answer is way off topic.
Again, I was looking for a scripting language that my noob self could be more comfortable in. It really came down to a question of language rather than the library itself. Oh, I am only using the TCP/IP stack at this time, which somewhat simplifies it as well.

Basic example of serial communication with Windows XP/win32

I am working with a peripheral device that needs to be communicated through serial. I can send it commands using HyperTerminal, but now I need to write programs that will let me do it without HyperTerminal. Can somebody point me to a website and/or show me a sample hello world program to get me started? I have searched through many sites which give me uncompilable/ancient VC6 code.
In order to interface with the serial port, you open a file with one of the special filenames "COM1" through "COM9". For serial ports with higher numbers, the special filename begins with \\?\, which in C/C++ code must be escaped as "\\\\?\\COM10", etc.
http://msdn.microsoft.com/en-us/library/ms810467.aspx has a really good tutorial on using the serial port. Note that you should use the Windows file I/O functions such as CreateFile(), ReadFile(), and WriteFile(). I'm not sure if it will work to use standard I/O functions such as fopen(), fread(), and fwrite().
Microsoft provides an article with sample code describing how to do this under Win32.
Boost:asio may be able to help as a serial device was added recently.
Fair warning though; the serial port documentation is light, presumably since it's quite new (it was added in asio 1.1.1 which was included in boost 1.36).
But working your way through asio is, IMHO, a better solution than using the raw Win32 API. Why? It'll be easier to read and maintain (it's a higher level API) and it'll be cross platform (except where you need to specify the OS-specific device name).
The Boost - Users and asio.user mailing lists are quite active and friendly and ought to be able to help you out if you get stuck.
If using .NET 2.0 see System.IO.Ports and this article should be helpful. If direct Win32, then Adam's answer is best.
I believe you will find plenty of sample code for C# as well if you find VC6 too ancient. I think there are also a bunch of "free" serial/COM port wrappers but I just wrote my own when I wrote an RS232 device controller piece of software.
google C# and serial port or rs232
I got these:
http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx
http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx
You should have no problem finding suitable code with a google search.

Resources