Skip to content

Commit

Permalink
Merge pull request #178 from smartdevicelink/fix/parsing_of_multi_fra…
Browse files Browse the repository at this point in the history
…me_messages_for_2_sessions

Fix parsing of multi-frame messages for 2 sessions
  • Loading branch information
jacobkeeler authored Sep 26, 2019
2 parents 024a563 + a1d4beb commit 37da7ab
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions modules/protocol_handler/protocol_handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ function ProtocolHandler.ProtocolHandler()
local ret =
{
buffer = "",
frames = { }
frames = { },
totalSize = { }
}
setmetatable(ret, mt)
return ret
Expand Down Expand Up @@ -276,24 +277,25 @@ function mt.__index:Parse(binary, validateJson, frameHandler)
or msg._technical.decryptionStatus == securityConstants.SECURITY_STATUS.ERROR then
table.insert(res, msg)
else
local key = "s"..msg.sessionId.."m"..msg.messageId
if msg.frameType == constants.FRAME_TYPE.CONTROL_FRAME then
table.insert(res, msg)
elseif msg.frameType == constants.FRAME_TYPE.FIRST_FRAME then
self.frames[msg.messageId] = ""
self.totalSize = msg.size
self.frames[key] = ""
self.totalSize[key] = msg.size
elseif msg.frameType == constants.FRAME_TYPE.SINGLE_FRAME then
if isBinaryDataHasHeader(msg) then
parseBinaryHeader(msg, validateJson)
end
table.insert(res, msg)
elseif msg.frameType == constants.FRAME_TYPE.CONSECUTIVE_FRAME then
self.frames[msg.messageId] = self.frames[msg.messageId] .. msg.binaryData
self.totalSize = self.totalSize + msg.size
self.frames[key] = self.frames[key] .. msg.binaryData
self.totalSize[key] = self.totalSize[key] + msg.size
if msg.frameInfo == constants.FRAME_INFO.LAST_FRAME then
msg.binaryData = self.frames[msg.messageId]
msg.size = self.totalSize
self.frames[msg.messageId] = nil
self.totalSize = nil
msg.binaryData = self.frames[key]
msg.size = self.totalSize[key]
self.frames[key] = nil
self.totalSize[key] = nil
if isBinaryDataHasHeader(msg) then
parseBinaryHeader(msg, validateJson)
end
Expand Down

0 comments on commit 37da7ab

Please sign in to comment.