Skip to content

Always encode size with MessageSet #771

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

Merged
merged 1 commit into from
Jul 17, 2016
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions kafka/protocol/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class MessageSet(AbstractType):
HEADER_SIZE = 12 # offset + message_size

@classmethod
def encode(cls, items, size=True, recalc_message_size=True):
def encode(cls, items):
# RecordAccumulator encodes messagesets internally
if isinstance(items, io.BytesIO):
size = Int32.decode(items)
Expand All @@ -156,8 +156,6 @@ def encode(cls, items, size=True, recalc_message_size=True):
encoded_values.append(Int64.encode(offset))
encoded_values.append(Bytes.encode(message))
encoded = b''.join(encoded_values)
if not size:
return encoded
return Bytes.encode(encoded)

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions test/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ def test_encode_message_set():
Message(b'v2', key=b'k2')
]
encoded = MessageSet.encode([(0, msg.encode())
for msg in messages],
size=False)
for msg in messages])
expect = b''.join([
struct.pack('>q', 0), # MsgSet Offset
struct.pack('>i', 18), # Msg Size
Expand All @@ -93,6 +92,7 @@ def test_encode_message_set():
struct.pack('>i', 2), # Length of value
b'v2', # Value
])
expect = struct.pack('>i', len(expect)) + expect
assert encoded == expect


Expand Down