-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2025 from Shopify/dnwe/apiversionsv3
feat: support ApiVersionsRequest V3 protocol
- Loading branch information
Showing
6 changed files
with
245 additions
and
64 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,69 @@ | ||
package sarama | ||
|
||
// ApiVersionsRequest ... | ||
type ApiVersionsRequest struct{} | ||
// const defaultClientSoftwareName = "sarama" | ||
|
||
type ApiVersionsRequest struct { | ||
// Version defines the protocol version to use for encode and decode | ||
Version int16 | ||
// ClientSoftwareName contains the name of the client. | ||
ClientSoftwareName string | ||
// ClientSoftwareVersion contains the version of the client. | ||
ClientSoftwareVersion string | ||
} | ||
|
||
func (r *ApiVersionsRequest) encode(pe packetEncoder) (err error) { | ||
if r.Version >= 3 { | ||
if err := pe.putCompactString(r.ClientSoftwareName); err != nil { | ||
return err | ||
} | ||
if err := pe.putCompactString(r.ClientSoftwareVersion); err != nil { | ||
return err | ||
} | ||
pe.putEmptyTaggedFieldArray() | ||
} | ||
|
||
func (a *ApiVersionsRequest) encode(pe packetEncoder) error { | ||
return nil | ||
} | ||
|
||
func (a *ApiVersionsRequest) decode(pd packetDecoder, version int16) (err error) { | ||
func (r *ApiVersionsRequest) decode(pd packetDecoder, version int16) (err error) { | ||
r.Version = version | ||
if r.Version >= 3 { | ||
if r.ClientSoftwareName, err = pd.getCompactString(); err != nil { | ||
return err | ||
} | ||
if r.ClientSoftwareVersion, err = pd.getCompactString(); err != nil { | ||
return err | ||
} | ||
if _, err := pd.getEmptyTaggedFieldArray(); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (a *ApiVersionsRequest) key() int16 { | ||
func (r *ApiVersionsRequest) key() int16 { | ||
return 18 | ||
} | ||
|
||
func (a *ApiVersionsRequest) version() int16 { | ||
return 0 | ||
func (r *ApiVersionsRequest) version() int16 { | ||
return r.Version | ||
} | ||
|
||
func (a *ApiVersionsRequest) headerVersion() int16 { | ||
func (r *ApiVersionsRequest) headerVersion() int16 { | ||
if r.Version >= 3 { | ||
return 2 | ||
} | ||
return 1 | ||
} | ||
|
||
func (a *ApiVersionsRequest) requiredVersion() KafkaVersion { | ||
return V0_10_0_0 | ||
func (r *ApiVersionsRequest) requiredVersion() KafkaVersion { | ||
switch r.Version { | ||
case 0: | ||
return V0_10_0_0 | ||
case 3: | ||
return V2_4_0_0 | ||
default: | ||
return V0_10_0_0 | ||
} | ||
} |
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
Oops, something went wrong.