-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add implementation of Kafka 0.11 Records #973
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
82babd0
Allow negative values for getArrayLength()
vlad-arista f554f21
Add support for Kafka 0.11 Record format.
vlad-arista 7630f80
Add support for Kafka 0.11 RecordBatch
vlad-arista e1067e3
Implement a sum type that can hold RecordBatch or MessageSet
vlad-arista 61fb33e
Rename Header to RecordHeader
vlad-arista 6d52b99
Add test coverage for Records.isControl() and Records.isPartial()
vlad-arista b37b158
Introduce dynamicPushEncoders
vlad-arista 371165d
Clarify the expected return value of ajustLength
vlad-arista 135aca9
Don't cache the length
vlad-arista b51e231
Make an encoder/decoder for records array
vlad-arista 5ffc7bf
Simplify uncompressed records length computation
vlad-arista 4a9a2bc
Get rid of size and adjusted fields in varintLengthField
vlad-arista c302872
Fix typo
vlad-arista bd304f1
Refactor record batch encoding
vlad-arista 033fed9
varintLengthField.reserveLen() should return 0 during decode
vlad-arista 808ea14
Check records encoding error
vlad-arista ff1f79c
Add dynamicPushDecoder interface
vlad-arista File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package sarama | ||
|
||
const ( | ||
controlMask = 0x20 | ||
) | ||
|
||
type RecordHeader struct { | ||
Key []byte | ||
Value []byte | ||
} | ||
|
||
func (h *RecordHeader) encode(pe packetEncoder) error { | ||
if err := pe.putVarintBytes(h.Key); err != nil { | ||
return err | ||
} | ||
return pe.putVarintBytes(h.Value) | ||
} | ||
|
||
func (h *RecordHeader) decode(pd packetDecoder) (err error) { | ||
if h.Key, err = pd.getVarintBytes(); err != nil { | ||
return err | ||
} | ||
|
||
if h.Value, err = pd.getVarintBytes(); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
type Record struct { | ||
Attributes int8 | ||
TimestampDelta int64 | ||
OffsetDelta int64 | ||
Key []byte | ||
Value []byte | ||
Headers []*RecordHeader | ||
|
||
length varintLengthField | ||
} | ||
|
||
func (r *Record) encode(pe packetEncoder) error { | ||
pe.push(&r.length) | ||
pe.putInt8(r.Attributes) | ||
pe.putVarint(r.TimestampDelta) | ||
pe.putVarint(r.OffsetDelta) | ||
if err := pe.putVarintBytes(r.Key); err != nil { | ||
return err | ||
} | ||
if err := pe.putVarintBytes(r.Value); err != nil { | ||
return err | ||
} | ||
pe.putVarint(int64(len(r.Headers))) | ||
|
||
for _, h := range r.Headers { | ||
if err := h.encode(pe); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return pe.pop() | ||
} | ||
|
||
func (r *Record) decode(pd packetDecoder) (err error) { | ||
if err = pd.push(&r.length); err != nil { | ||
return err | ||
} | ||
|
||
if r.Attributes, err = pd.getInt8(); err != nil { | ||
return err | ||
} | ||
|
||
if r.TimestampDelta, err = pd.getVarint(); err != nil { | ||
return err | ||
} | ||
|
||
if r.OffsetDelta, err = pd.getVarint(); err != nil { | ||
return err | ||
} | ||
|
||
if r.Key, err = pd.getVarintBytes(); err != nil { | ||
return err | ||
} | ||
|
||
if r.Value, err = pd.getVarintBytes(); err != nil { | ||
return err | ||
} | ||
|
||
numHeaders, err := pd.getVarint() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if numHeaders >= 0 { | ||
r.Headers = make([]*RecordHeader, numHeaders) | ||
} | ||
for i := int64(0); i < numHeaders; i++ { | ||
hdr := new(RecordHeader) | ||
if err := hdr.decode(pd); err != nil { | ||
return err | ||
} | ||
r.Headers[i] = hdr | ||
} | ||
|
||
return pd.pop() | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why cast to int32 and then int?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we want to convert it to a signed value, so we're converting it to its signed counterpart (int usually 64 bits on 64bit platforms, so the sign conversion won't happen).