Implement the representations for Kafka ApiVersions

This commit is contained in:
M. Mert Yildiran 2021-08-22 16:05:14 +03:00
parent 2d0d583a93
commit 89eb0e0f9a
No known key found for this signature in database
GPG Key ID: D42ADB236521BF7A
2 changed files with 71 additions and 0 deletions

View File

@ -177,3 +177,70 @@ func representMetadataResponse(data map[string]interface{}) []interface{} {
return rep
}
func representApiVersionsRequest(data map[string]interface{}) []interface{} {
rep := make([]interface{}, 0)
rep = representRequestHeader(data, rep)
payload := data["Payload"].(map[string]interface{})
clientSoftwareName := ""
clientSoftwareVersion := ""
if payload["ClientSoftwareName"] != nil {
clientSoftwareName = payload["ClientSoftwareName"].(string)
}
if payload["ClientSoftwareVersion"] != nil {
clientSoftwareVersion = payload["ClientSoftwareVersion"].(string)
}
repPayload, _ := json.Marshal([]map[string]string{
{
"name": "Client Software Name",
"value": clientSoftwareName,
},
{
"name": "Client Software Version",
"value": clientSoftwareVersion,
},
})
rep = append(rep, map[string]string{
"type": "table",
"title": "Payload",
"data": string(repPayload),
})
return rep
}
func representApiVersionsResponse(data map[string]interface{}) []interface{} {
rep := make([]interface{}, 0)
rep = representResponseHeader(data, rep)
payload := data["Payload"].(map[string]interface{})
apiKeys, _ := json.Marshal(payload["ApiKeys"].([]interface{}))
throttleTimeMs := ""
if payload["ThrottleTimeMs"] != nil {
throttleTimeMs = fmt.Sprintf("%d", int(payload["ThrottleTimeMs"].(float64)))
}
repPayload, _ := json.Marshal([]map[string]string{
{
"name": "Error Code",
"value": fmt.Sprintf("%d", int(payload["ErrorCode"].(float64))),
},
{
"name": "ApiKeys",
"value": string(apiKeys),
},
{
"name": "Throttle Time (ms)",
"value": throttleTimeMs,
},
})
rep = append(rep, map[string]string{
"type": "table",
"title": "Payload",
"data": string(repPayload),
})
return rep
}

View File

@ -177,6 +177,10 @@ func (d dissecting) Represent(entry string) ([]byte, error) {
repRequest = representMetadataRequest(reqDetails)
repResponse = representMetadataResponse(resDetails)
break
case ApiVersions:
repRequest = representApiVersionsRequest(reqDetails)
repResponse = representApiVersionsResponse(resDetails)
break
}
representation["request"] = repRequest