C++ how to send protobuf message - c++

Can somebody please give me some sample code to do this? I've been reading and looking at the tutorials but they all seem to cover how to create proto files and generate your message classes and how to populated the message. I cannot figure out how to actually send the message once I have it.
Here I am populating my message:
TestMessage message;
message.set_personname("Lucy");
message.set_image(data, elemSize);
string out;
message.SerializeToString(&out);
Did that serialize the message or do I still need to write it out to a buffer? I need to check this code but I believe the object serialized to a string might do what I need for protobufs.
Once I have a serialized class to send, what does the code look like to transmit over http to a url? I mean are there Google provided methods to do this? If so, where are they? If not, then what should I use?
Please note that I am a complete noob at C++. So please forgive me if it seems as if I didn't do enough research. It's just that the more I look the more confused I get. There seems to be so many options. Just one will do.

Related

Sending a binary message with RabbitQM SimpleAmqpClient

I'm writing in C++ and want to send binary data (Serialized Google Protobufs) using the SimpleAmqpClient library. The only message type I see is BasicMessage. The only way to populate a BasicMessage seems to be with an std::string. Is publishing a BasicMessage with an std::string holding binary data (GProtobufs serialize themselves this way) going to work?
So I got around to trying this. Initializing a BasicMessage from a string with binary data including nulls does work as I had hoped. I would feel better if I knew this was an intentionally supported feature and part of the SimpleAmqpClient test suite.
I previously posted that it worked; then posted that it didn't. Well it actually does.

How should I go about serving a json file to a website in my current architecture

sorry for absolutly murdering the tilte. But I am not sure how to frame this question, please edit this if there is a better way of explaining my problem.
I am reading a bitstream from a program which I convert into json data, write it to a socket, where another program reads this data and appends it to a log.json file. I am doing all of this in C++
Now I want to display this data in a better way. So why not try to display this in an html document, with some css applied on it.
My first thought was to simply fetch this with javascript. But now-a-days this throws an error.
So my second thought was to create a simple node.js server which accepts GET requests and then use this to serve the file. But this feels like its a bit overkill.
My third thought is now to perhaps use my original server (who continuously reads from the socket). And use that one to also accept http requests. But then I would have to multithread it, which again seems kinda overkill.
So im kinda falling back to needing 2 different "servers". One that reads from the socket and appends to the log file and another to serve this file to the website.
Am I'm thinking wrong here? What would be a good way to solve this?

Mime message with attachment turns as empty spam using libcurl

I'm trying to write a small smtp client in c++ using libcurl. I managed to send simple text email quite easily, but I'm failing when it comes to attachment...
For some weird reason, with my current implementation, some messages are correctly sent and received like this one
http://hastebin.com/cifetowiya.scala
whereas others are constantly failing and transformed into an empty message, like this one
http://hastebin.com/mafemufaxu.go
I spent some time looking around but I can't find any reason for that. Any help would be more than welcome!
Thanks a lot!
Edit:
I found my problem. The mime message is correct, but too long, and was exceeding the size my lib was currently able to handle. I fixed it and it's now working like a charm. See here for more explanation: https://codereview.stackexchange.com/questions/140805/sending-email-using-libcurl-follow-up-2/144208#144208

How to create a dynamic message with Protocol Buffers?

Say we want to create our message not using any preexisting .proto files and compiled out from them cpp/cxx/h files. We want to use protobuf strictly as a library. For example we got (in some only known to us format) message description: a message called MyMessage has to have MyIntFiels and optional MyStringFiels. How to create such message? for example fill it with simple data save to .bin and read from that binary its contents back?
I looked all over dynamic_message.h help description and DescriptorPool and so on but do not see how to add/remove fields to the message as well as no way to add described on fly message to DescriptorPool.
Can any one please explain?
Short answer: it can't be used that way.
The overview page of Protobuf says:
XML is also – to some extent – self-describing. A protocol buffer is only meaningful if you have the message definition (the .proto file).
Meaning the whole point of Protobuf is to throw-out self-descriptability in favor of parsing speed ==> it's just not it's purpose to create self describing messages.
Consider using XML or JSON or any other serialization format. If the protection is needed, you can use symmetric encryption and/or lzip compression.

File Signature Validation

I Have used a utility written by Mark Russinovich, it is used to validate the file signature.
Any one have ideas how this can be done, i know it is not a simple code, but just i need some hints, APIs, steps, A guide map, Just to go in the correct direction.
I read too much a bout the cryptAPIs, then I read too much about the certAPIs, but i cannot get any thing useful to simply link a given file with the (unknown to me) data stored in the windows.
if any can help me in this issue please help, thanks a lot.
You should read about Authenticode.