summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Han <jeffreyhan@fb.com>2020-10-01 16:17:17 -0700
committerJens Geyer <jensg@apache.org>2020-10-02 22:02:56 +0200
commit5751ddf2ac8df7845c88154a9cc498c46402730d (patch)
tree54f3b1490a17e841a0e9fdcd3b3d364d56884fc4
parent330482b02e14955b7a760c59214de3e1b6d03dce (diff)
downloadthrift-5751ddf2ac8df7845c88154a9cc498c46402730d.tar.gz
THRIFT-5286: Fix Lua library readBool() in TCompactProtocol
Client: Lua Patch: Jeffrey Han This closes #2252
-rw-r--r--lib/lua/TCompactProtocol.lua20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/lua/TCompactProtocol.lua b/lib/lua/TCompactProtocol.lua
index ca488dc7b..0ebccac7a 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