Skip to content

Commit 384acd4

Browse files
committed
fix: enforce minimum version requirement in ApiVersionsRequestBody encoding
- Added a panic condition in the Encode method of ApiVersionsRequestBody to ensure that the Version is always >= 3, preventing potential runtime errors. - Refactored the Encode method in ApiVersionsRequest to utilize a common encodeRequest function, improving code consistency and readability.
1 parent 40130de commit 384acd4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

protocol/api/api_versions_request.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ type ApiVersionsRequestBody struct {
1515
}
1616

1717
func (r ApiVersionsRequestBody) Encode(enc *encoder.Encoder) {
18-
if r.Version >= 3 {
19-
enc.PutCompactString(r.ClientSoftwareName)
20-
enc.PutCompactString(r.ClientSoftwareVersion)
21-
enc.PutEmptyTaggedFieldArray()
18+
if r.Version < 3 {
19+
panic("CodeCrafers Internal Error: ApiVersionsRequestBody.Version must be >= 3")
2220
}
21+
22+
enc.PutCompactString(r.ClientSoftwareName)
23+
enc.PutCompactString(r.ClientSoftwareVersion)
24+
enc.PutEmptyTaggedFieldArray()
2325
}
2426

2527
type ApiVersionsRequest struct {

0 commit comments

Comments
 (0)