[
https://issues.apache.org/jira/browse/THRIFT-3650?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15156037#comment-15156037
]
ASF GitHub Bot commented on THRIFT-3650:
----------------------------------------
GitHub user Jens-G opened a pull request:
https://github.com/apache/thrift/pull/881
THRIFT-3650 union (and optionals) serialization
Contains all fixes for THRIFT-3650, 3652, 3654 and 3656 (4 patches)
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/Jens-G/thrift THRIFT-3650
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/thrift/pull/881.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #881
----
commit 4606783164233330ae9171ea998cf5c5f9ce9475
Author: Jens Geyer <[email protected]>
Date: 2016-02-21T14:07:51Z
THRIFT-3650 incorrect union serialization Client: Compiler (general) Patch:
Jens Geyer
commit beab25cb84ae77692417345dbddadfa65cfca385
Author: Jens Geyer <[email protected]>
Date: 2016-02-21T14:14:41Z
THRIFT-3654 incorrect serialization of optionals Client: Haxe Patch: Jens
Geyer
commit 6a1fb354f24e1e48b4767ec8d54bb66ed984555a
Author: Jens Geyer <[email protected]>
Date: 2016-02-21T14:19:45Z
THRIFT-3652 incorrect serialization of optionals Client: AS3 Patch: Jens
Geyer
commit 695d5cb7a75f9e2d3625e7c342d6ef5101f5f774
Author: Jens Geyer <[email protected]>
Date: 2016-02-21T14:23:37Z
THRIFT-3656 incorrect serialization of optionals Client: Dart Patch: Jens
Geyer
----
> incorrect union serialization
> ------------------------------
>
> Key: THRIFT-3650
> URL: https://issues.apache.org/jira/browse/THRIFT-3650
> Project: Thrift
> Issue Type: Bug
> Components: C++ - Compiler, Compiler (General)
> Affects Versions: 0.9.3
> Reporter: Jens Geyer
> Assignee: Jens Geyer
> Attachments: 0001-THRIFT-3650-incorrect-union-serialization.patch
>
>
> With C++ the following {{union}} generates incorrect serialization code:
> {code}
> union type_ex {
> 1 : string foo
> 2 : i32 bar
> 3 : double baz
> }
> {code}
> This results in all three fields being *unconditionally* written, which not
> only wastes space on the wire, but also sets all {{__isset}} bits during
> deserialization. This makes it a bit hard to the other side to find out which
> {{union}} field is the right one.
> {code}
> uint32_t type_ex::write(::apache::thrift::protocol::TProtocol* oprot) const {
> uint32_t xfer = 0;
> apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot);
> xfer += oprot->writeStructBegin("type_ex");
> xfer += oprot->writeFieldBegin("STRING",
> ::apache::thrift::protocol::T_STRING, 1);
> xfer += oprot->writeString(this->STRING);
> xfer += oprot->writeFieldEnd();
> xfer += oprot->writeFieldBegin("INT64", ::apache::thrift::protocol::T_I64,
> 2);
> xfer += oprot->writeI64(this->INT64);
> xfer += oprot->writeFieldEnd();
> xfer += oprot->writeFieldBegin("DOUBLE",
> ::apache::thrift::protocol::T_DOUBLE, 3);
> xfer += oprot->writeDouble(this->DOUBLE);
> xfer += oprot->writeFieldEnd();
> xfer += oprot->writeFieldStop();
> xfer += oprot->writeStructEnd();
> return xfer;
> }
> {code}
> *Note* that the code above is just right (due to "default" requiredness) if
> we talk about structs. But these rules do not really apply to union members
> where *by definition* only one value is used. Hence, union members implicitly
> have {{optional}} requiredness
> *Workaround*
> Add explicit {{optionals}}:
> {code}
> union type_ex {
> 1 : optional string foo
> 2 : optional i32 bar
> 3 : optional double baz
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)