Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cql) support for custom payload in response frames #119

Merged
merged 2 commits into from
Oct 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions lib/cassandra/cql.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ local OP_CODES = {
local FRAME_FLAGS = {
--COMPRESSION = 0x01,
TRACING = 0x02,
--CUSTOM_PAYLOAD = 0x04,
CUSTOM_PAYLOAD = 0x04,
WARNING = 0x08,
}

Expand Down Expand Up @@ -484,6 +484,19 @@ do
return {fields = fields}
end

local function unmarsh_bytes_map(buffer)
local n = buffer:read_short()

local fields = {}
for _ = 1, n do
local key = buffer:read_string()
local value = buffer:read_bytes()
fields[key] = value
end

return fields
end

do
local marshallers = {
byte = {marsh_byte, unmarsh_byte},
Expand All @@ -500,7 +513,8 @@ do
string_list = {marsh_string_list, unmarsh_string_list},
string_multimap = {marsh_string_multimap, unmarsh_string_multimap},
udt_type = {nil, unmarsh_udt_type},
tuple_type = {nil, unmarsh_tuple_type}
tuple_type = {nil, unmarsh_tuple_type},
bytes_map = {nil, unmarsh_bytes_map}
}

for name, t in pairs(marshallers) do
Expand Down Expand Up @@ -1362,14 +1376,18 @@ do
local op_code = header.op_code
local body = Buffer.new(header.version, bytes)

local tracing_id, warnings
if band(header.flags, FRAME_FLAGS.TRACING) ~= 0 then
tracing_id = body:read_uuid()
end
if band(header.flags, FRAME_FLAGS.CUSTOM_PAYLOAD) ~= 0 then
body:read_bytes_map() -- discard
end
if band(header.flags, FRAME_FLAGS.WARNING) ~= 0 then
warnings = body:read_string_list()
end

if op_code == OP_CODES.RESULT then
local tracing_id, warnings
if band(header.flags, FRAME_FLAGS.TRACING) ~= 0 then
tracing_id = body:read_uuid()
end
if band(header.flags, FRAME_FLAGS.WARNING) ~= 0 then
warnings = body:read_string_list()
end
local result_kind = body:read_int()
local parser = results_parsers[result_kind]
local res = parser(body)
Expand Down