thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nobuaki Sukegawa <nsu...@gmail.com>
Subject Re: Serializing struct using c_glib into memory buffer Help!
Date Thu, 26 Nov 2015 22:25:35 GMT
It is strange, the generated header has rdata_write ?
Seeing generated code, it should be something like this:

ThriftStructClass* cls = THRIFT_STRUCT_CLASS(RDATA_GET_CLASS(pData));
cls->write(pData->parent, protocol, &error);

On Thu, Nov 26, 2015 at 8:03 AM GZ <gz@zygmund.net> wrote:

> I am new to thrift and have been trying to serialize a thrift structure
> using c but have been unable to get it to work. I want to serialize using
> the binary protocol into a memory buffer. I do not need RPC, I will be
> passing the message into Kafka. Does anyone know the correct way to do this?
>
> I have looked through all the examples and test code and have come up with
> the following. It compiles, but is not working correctly. I am clearly not
> doing it correctly. rdata_write is a method generated by thrift.
>
>     GError *error = NULL;
>     ThriftTransport *transport = NULL;
>     ThriftProtocol *protocol = NULL;
>
>     transport=g_object_new (THRIFT_TYPE_MEMORY_BUFFER, "buf_size", 100,
> NULL);
>     if(transport){
>         thrift_transport_open (transport, &error);
>         protocol = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
> transport,NULL);
>         if(protocol){
>             rdata* pData = g_object_new (TYPE_RDATA,"flag",1,
>                                     "id",27,
>                                     "start",12000,
>                                     "done",345435,
>                                     "notif",34455,
>                                     "spid","This is the SPID",NULL);
>             if(pData){
>
>                 /* wanted something like obj->write(protocol,&error)
>                    But how to get object? pData does not have write method
> */
>
>                 gint32 len =
> rdata_write(pData,(ThriftProtocol*)protocol,&error);
>
>                 // Print Content of Buffer
>                 ThriftMemoryBuffer* pMem = (ThriftMemoryBuffer*)transport;
>                 if(pMem->buf != NULL){
>                     printHex((const void *)pMem->buf, len);
>                 }
>                 g_object_unref (pData);
>             }
>             g_object_unref (protocol);
>         }
>         g_object_unref(transport);
>     }
>
> Error handling and support functions skipped for brevity.
>
> Any help appreciated
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message