You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by Rajesh Khan <ra...@gmail.com> on 2012/10/23 00:40:50 UTC

How would you receive this C++ List in C#

Hi , I have something like this in my C++ program

    qpid::types::Variant::Map content;
    content["keyA"] = "ValA";
    content["KeyB"] = "ValB"

    qpid::types::Variant::List object;
    object.push_back(content);

    encode(object,message);
    sender_.send(message);

Now in my C# I have something like this
if ("amqp/list" == message_.ContentType)
{
                        Collection<object> content = new
Collection<object>();
                        message_.GetContent(content);
                        //How could I get a Dictinary from this ?
}

Re: How would you receive this C++ List in C#

Posted by Chuck Rolke <cr...@redhat.com>.
For using the .NET Binding please see cpp\bindings\qpid\dotnet\esamples\csharp.map.sender\csharp.map.sender.cs. The encoding is built right in to the Message constructor. There is a map.receiver example that shows receiving the map message.

-Chuck

            //
            // Create structured content for the message.  This example builds a
            // map of items including a nested map and a list of values.
            //
            Dictionary<string, object> content = new Dictionary<string, object>();
            Dictionary<string, object> subMap = new Dictionary<string, object>();
            Collection<object> colors = new Collection<object>();

            // add simple types
            content["id"] = 987654321;
            content["name"] = "Widget";
            content["percent"] = 0.99;

            // add nested amqp/map
            subMap["name"] = "Smith";
            subMap["number"] = 354;
            content["nestedMap"] = subMap;

            // add an amqp/list
            colors.Add("red");
            colors.Add("green");
            colors.Add("white");
            // list contains null value
            colors.Add(null);
            content["colorsList"] = colors;

            // add one of each supported amqp data type
            bool mybool = true;
            content["mybool"] = mybool;

            byte mybyte = 4;
            content["mybyte"] = mybyte;

            UInt16 myUInt16 = 5 ;
            content["myUInt16"] = myUInt16;

            UInt32 myUInt32 = 6;
            content["myUInt32"] = myUInt32;

            UInt64 myUInt64 = 7;
            content["myUInt64"] = myUInt64;

            char mychar = 'h';
            content["mychar"] = mychar;

            Int16 myInt16 = 9;
            content["myInt16"] = myInt16;

            Int32 myInt32 = 10;
            content["myInt32"] = myInt32;

            Int64 myInt64 = 11;
            content["myInt64"] = myInt64;

            Single mySingle = (Single)12.12;
            content["mySingle"] = mySingle;

            Double myDouble = 13.13;
            content["myDouble"] = myDouble;

            Guid myGuid = new Guid("000102030405060708090a0b0c0d0e0f");
            content["myGuid"] = myGuid;

            content["myNull"] = null;

            //
            // Construct a message with the map content and send it synchronously
            // via the sender.
            //
            Message message = new Message(content);
            sender.Send(message, true);


----- Original Message -----
> From: "Pavel Moravec" <pm...@redhat.com>
> To: users@qpid.apache.org
> Sent: Tuesday, October 23, 2012 2:06:30 AM
> Subject: Re: How would you receive this C++ List in C#
> 
> Hi Rajesh,
> I have almost no experience with C# bindings but I suppose you must
> use method
> 
>     void TypeTranslator::NativeToManaged(::qpid::types::Variant::Map
>     & qpidMap,
>                                                                                  QpidMap
>                                                                                  ^
>                                                                                  dict)
>     {
>         // For each object in the message map,
>         //  create a .NET object and add it to the dictionary.
> 
> 
> (and TypeTranslator::ManagedToNative for reverse conversion)
> 
> Kind regards,
> Pavel Moravec
> 
> 
> ----- Original Message -----
> > From: "Rajesh Khan" <ra...@gmail.com>
> > To: users@qpid.apache.org
> > Sent: Tuesday, October 23, 2012 12:40:50 AM
> > Subject: How would you receive this C++ List in C#
> > 
> > Hi , I have something like this in my C++ program
> > 
> >     qpid::types::Variant::Map content;
> >     content["keyA"] = "ValA";
> >     content["KeyB"] = "ValB"
> > 
> >     qpid::types::Variant::List object;
> >     object.push_back(content);
> > 
> >     encode(object,message);
> >     sender_.send(message);
> > 
> > Now in my C# I have something like this
> > if ("amqp/list" == message_.ContentType)
> > {
> >                         Collection<object> content = new
> > Collection<object>();
> >                         message_.GetContent(content);
> >                         //How could I get a Dictinary from this ?
> > }
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: How would you receive this C++ List in C#

Posted by Pavel Moravec <pm...@redhat.com>.
Hi Rajesh,
I have almost no experience with C# bindings but I suppose you must use method

    void TypeTranslator::NativeToManaged(::qpid::types::Variant::Map & qpidMap,
                                                                                 QpidMap ^ dict)
    {
        // For each object in the message map, 
        //  create a .NET object and add it to the dictionary.


(and TypeTranslator::ManagedToNative for reverse conversion)

Kind regards,
Pavel Moravec


----- Original Message -----
> From: "Rajesh Khan" <ra...@gmail.com>
> To: users@qpid.apache.org
> Sent: Tuesday, October 23, 2012 12:40:50 AM
> Subject: How would you receive this C++ List in C#
> 
> Hi , I have something like this in my C++ program
> 
>     qpid::types::Variant::Map content;
>     content["keyA"] = "ValA";
>     content["KeyB"] = "ValB"
> 
>     qpid::types::Variant::List object;
>     object.push_back(content);
> 
>     encode(object,message);
>     sender_.send(message);
> 
> Now in my C# I have something like this
> if ("amqp/list" == message_.ContentType)
> {
>                         Collection<object> content = new
> Collection<object>();
>                         message_.GetContent(content);
>                         //How could I get a Dictinary from this ?
> }
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org