We help IT Professionals succeed at work.
Get Started
Troubleshooting Question

How do I convert the c# code to c++?

Shivani Sarin
Last Modified: 2020-11-04
I have a code in C# that I am finding it a bit difficult to convert to c++.
I have data formatted in a certain way in c# and want to be able to do the same with c++. Goal- Generate similar serialized data from c# in C++..
Dictionary<string, object> dict = new Dictionary<string, object>(); 
dict.Add("Time", "2015-11-21 21:34:34.881"); 
dict.Add("Risk", "Medium");    
Dictionary<string, object> msgpackOptions = new Dictionary<string, object>(); msgpackOptions.Add("TimeFormat", "DateTime");    
object[] item = new object[] { DateTime.UtcNow, dict };
object[] obj = new object[] { "TestName" , new object[] { item }, msgpackOptions };    //Using MessagePackSerializer class in c# to perform the serialization
byte[] message = MessagePackSerializer.Serialize(obj);
//writing to a pipe client(using PipeControl class in c#, not elaborated here, since I don't really need help with this, but just want to mention end goal of serilaizing using fluentd and writing to the pipe)                           
pipeClient.Write(message, 0, message.Length);
Here is what I have implemented, but I am confused about line 11 and which data structure would be best for this. Below is my code in c++, I am using msgpack library from https://www.nuget.org/packages/msgpack-c/ to send packets after serializing(which is done by msgpack::pack function)
typedef std::map<std::string, std::string> dicts; 
dicts dict; 
dict["Time"] = "2015-11-21 21:34:34.881"; 
dict["Risk"] = "Medium";                            
typedef std::map<std::string, dicts> dictionary; 
dictionary item;
item["2020"] = dict; //this "2020", should be the current datetime format...
typedef std::map<std::string, dictionary> final;
final obj; 
msgpack::sbuffer buffer; 
If any more information is needed, happy to provide that incase I have missed out anything.Just need some guidance/tips as to what can I do here.Also, if there is a way to see the serialized data in c# that would be very helpful. Thanks :)
Watch Question
This question hasn't been answered yet.
While you wait, find out how you can maximize your capability with the most trusted tool in IT.
Explore More Ask a Question
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE