You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Jens Geyer (JIRA)" <ji...@apache.org> on 2016/02/26 20:38:18 UTC

[jira] [Commented] (THRIFT-3675) Union is not serialized correctly by Thrift C Glib

    [ https://issues.apache.org/jira/browse/THRIFT-3675?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15169635#comment-15169635 ] 

Jens Geyer commented on THRIFT-3675:
------------------------------------

off-topic: naming a {{struct JLException}} that is not an {{exception}} is an interesting approach :-)

> Union is not serialized correctly by Thrift C Glib
> --------------------------------------------------
>
>                 Key: THRIFT-3675
>                 URL: https://issues.apache.org/jira/browse/THRIFT-3675
>             Project: Thrift
>          Issue Type: Bug
>          Components: C glib - Library
>    Affects Versions: 0.9.3
>            Reporter: Alexandr Rewa
>            Assignee: Jens Geyer
>             Fix For: 0.1.0
>
>
> I am trying to serialize Thrift union in C and then deserialize in Java. On Java side I always get serialized only first field of union. The following code works correctly with structs but not with union only.
> Thrift 0.9.3
> *messages.thrift:*
> {code}
> struct JLException {
> ...
> }
> struct JLFrame {
> ...
> }
> union JLMessage {
>     1: JLException exc,
>     2: JLFrame frame
> }
> {code}
> *Serialization code in C* (I replaced with "..." unnecessary parts):
> {code}
> JLException* jlExeption = g_object_new(TYPE_J_L_EXCEPTION, ... , NULL);
> if (jlExeption) {
>     JLMessage* jlMessage = g_object_new(TYPE_J_L_MESSAGE, "exc", jlExeption, NULL);
>     serialize_and_send_thrift_message((ThriftStruct*) jlMessage,
>         THRIFT_STRUCT_CLASS(J_L_MESSAGE_GET_CLASS(jlMessage)));
>     g_object_unref(jlExeption);
>     g_object_unref(jlMessage);
> }
> JLFrame* jlFrame = g_object_new(TYPE_J_L_FRAME, ... , NULL);
> if (jlFrame) {
>     JLMessage* jlMessage = g_object_new(TYPE_J_L_MESSAGE, "frame", jlFrame,
>         NULL);
>     serialize_and_send_thrift_message((ThriftStruct*) jlMessage,
>         THRIFT_STRUCT_CLASS(J_L_MESSAGE_GET_CLASS(jlMessage)));
>     g_object_unref(jlFrame);
>     g_object_unref(jlMessage);
> }
> {code}
> *Deserialization code in Java:*
> {code}
> TDeserializer deserializer = new TDeserializer();
> JLMessage message = new JLMessage();
> try {
>     byte[] binData = tuple.getBinary(0);
>     deserializer.deserialize(message, binData);
> } catch (TException e) {
>     _logger.error(e);
> }
> if (JLMessage._Fields.EXC.equals(message.getSetField())) {
>     _logger.info("Received EXCEPTION message");
> } else if (JLMessage._Fields.FRAME.equals(message.getSetField())) {
>     _logger.info("Received FRAME message");
> }
> {code}
> As a result on Java side only "Received EXCEPTION message" is logged. For JLFrame messages it receives empty JLException message.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)