You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2020/10/02 20:04:14 UTC

[thrift] branch master updated: THRIFT-5286: Fix Lua library readBool() in TCompactProtocol Client: Lua Patch: Jeffrey Han

This is an automated email from the ASF dual-hosted git repository.

jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new 5751ddf  THRIFT-5286: Fix Lua library readBool() in TCompactProtocol Client: Lua Patch: Jeffrey Han
5751ddf is described below

commit 5751ddf2ac8df7845c88154a9cc498c46402730d
Author: Jeffrey Han <je...@fb.com>
AuthorDate: Thu Oct 1 16:17:17 2020 -0700

    THRIFT-5286: Fix Lua library readBool() in TCompactProtocol
    Client: Lua
    Patch: Jeffrey Han
    
    This closes #2252
---
 lib/lua/TCompactProtocol.lua | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/lib/lua/TCompactProtocol.lua b/lib/lua/TCompactProtocol.lua
index ca488dc..0ebccac 100644
--- a/lib/lua/TCompactProtocol.lua
+++ b/lib/lua/TCompactProtocol.lua
@@ -176,7 +176,6 @@ function TCompactProtocol:writeBool(bool)
   if bool then
     value = TCompactType.COMPACT_BOOLEAN_TRUE
   end
-  print(value,self.booleanFieldPending,self.booleanFieldId)
   if self.booleanFieldPending then
     self:writeFieldBeginInternal(self.booleanFieldName, TType.BOOL, self.booleanFieldId, value)
     self.booleanFieldPending = false
@@ -293,17 +292,20 @@ function TCompactProtocol:readFieldBegin()
   if ttype == TType.STOP then
     return nil, ttype, 0
   end
-  -- mask off the 4 MSB of the type header. it could contain a field id delta.
-  local modifier = libluabitwise.shiftr(libluabitwise.band(field_and_ttype, 0xf0), 4)
+  local modifier = libluabitwise.shiftr(field_and_ttype, 4)
   local id = 0
   if modifier == 0 then
     id = self:readI16()
   else
     id = self.lastFieldId + modifier
   end
-  if ttype == TType.BOOL then
-    boolValue = libluabitwise.band(field_and_ttype, 0x0f) == TCompactType.COMPACT_BOOLEAN_TRUE
-    boolValueIsNotNull = true
+  local type = libluabitwise.band(field_and_ttype, 0x0f)
+  if type == TCompactType.COMPACT_BOOLEAN_TRUE then
+    self.boolValue = true
+    self.boolValueIsNotNull = true
+  elseif type == TCompactType.COMPACT_BOOLEAN_FALSE then
+    self.boolValue = false
+    self.boolValueIsNotNull = true
   end
   self.lastFieldId = id
   return nil, ttype, id
@@ -350,9 +352,9 @@ function TCompactProtocol:readSetEnd()
 end
 
 function TCompactProtocol:readBool()
-  if boolValueIsNotNull then
-    boolValueIsNotNull = true
-    return boolValue
+  if self.boolValueIsNotNull then
+    self.boolValueIsNotNull = false
+    return self.boolValue
   end
   local val = self:readSignByte()
   if val == TCompactType.COMPACT_BOOLEAN_TRUE then