Repository: thrift
Updated Branches:
  refs/heads/master 83494259d -> 2aa04bf38


THRIFT-3028 Regression caused by THRIFT-2180
Client: Cooca
Patch: Jeremy W. Sherman


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/2aa04bf3
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/2aa04bf3
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/2aa04bf3

Branch: refs/heads/master
Commit: 2aa04bf384a65e8a5ea3f996b790d231aa279626
Parents: 8349425
Author: Jens Geyer <[email protected]>
Authored: Fri Apr 17 18:44:37 2015 +0200
Committer: Jens Geyer <[email protected]>
Committed: Fri Apr 17 18:44:37 2015 +0200

----------------------------------------------------------------------
 lib/cocoa/src/protocol/TBinaryProtocol.m | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/2aa04bf3/lib/cocoa/src/protocol/TBinaryProtocol.m
----------------------------------------------------------------------
diff --git a/lib/cocoa/src/protocol/TBinaryProtocol.m 
b/lib/cocoa/src/protocol/TBinaryProtocol.m
index e79bd57..847c723 100644
--- a/lib/cocoa/src/protocol/TBinaryProtocol.m
+++ b/lib/cocoa/src/protocol/TBinaryProtocol.m
@@ -21,16 +21,10 @@
 #import "TProtocolException.h"
 #import "TObjective-C.h"
 
+/* In the modern protocol, version is stored in the high half of an int32.
+ * The low half contains type info. */
 static const uint16_t VERSION_1 = 0x8001;
 
-union versioned_size {
-  int32_t i32;
-  struct {
-    uint16_t version;
-    int16_t size;
-  } packed;
-};
-
 NS_INLINE size_t
 CheckedCastInt32ToSizeT(int32_t size)
 {
@@ -164,9 +158,8 @@ static TBinaryProtocolFactory * gSharedFactory = nil;
 {
   int32_t size = [self readI32];
   if (size < 0) {
-    union versioned_size vsize;
-    vsize.i32 = size;
-    uint16_t version = vsize.packed.version;
+    /* Version (unsigned) is stored in the high halfword. */
+    uint16_t version = (size >> 16) & 0xFFFF;
     if (version != VERSION_1) {
       NSString *reason = [NSString stringWithFormat:
                           @"%s: Expected version %"PRIu16", instead found: 
%"PRIu16,
@@ -394,7 +387,7 @@ static TBinaryProtocolFactory * gSharedFactory = nil;
                         sequenceID: (int) sequenceID
 {
   if (mStrictWrite) {
-    int version = VERSION_1 | messageType;
+    int version = (VERSION_1 << 16) | messageType;
     [self writeI32: version];
     [self writeString: name];
     [self writeI32: sequenceID];

Reply via email to