MINOR: comment apikey types in generated switch (#8201)

As a developer, it would be convenient if the generated
{request,response}HeaderVersion case statements in ApiMessageType.java
included a comment to remind me which type each of them is so I don't
need to manually cross-reference the newer/rarer ones.

Also include commented lines for the two special cases around
ApiVersionsResponse and ControllerShutdownRequest which are hardcoded in
the ApiMessageTypeGenerator.java and not covered by the message format
json files.

Before:
```java
    public short requestHeaderVersion(short _version) {
        switch (apiKey) {
            case 0:
                return (short) 1;
            case 1:
                return (short) 1;
            case 2:
                return (short) 1;
            case 3:
                if (_version >= 9) {
                    return (short) 2;
                } else {
                    return (short) 1;
                }
            // ...etc
```

After:
```java
    public short requestHeaderVersion(short _version) {
        switch (apiKey) {
            case 0: // Produce
                return (short) 1;
            case 1: // Fetch
                return (short) 1;
            case 2: // ListOffset
                return (short) 1;
            case 3: // Metadata
                if (_version >= 9) {
                    return (short) 2;
                } else {
                    return (short) 1;
                }
            // ...etc
```

Signed-off-by: Dominic Evans <dominic.evans@uk.ibm.com>

Reviewers: Mickael Maison <mickael.maison@gmail.com>
This commit is contained in:
Dominic Evans 2020-03-15 10:46:09 +00:00 committed by GitHub
parent 2e6b15813c
commit ddd3dfbfae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -256,19 +256,21 @@ public final class ApiMessageTypeGenerator {
buffer.incrementIndent(); buffer.incrementIndent();
for (Map.Entry<Short, ApiData> entry : apis.entrySet()) { for (Map.Entry<Short, ApiData> entry : apis.entrySet()) {
short apiKey = entry.getKey(); short apiKey = entry.getKey();
buffer.printf("case %d:%n", apiKey); ApiData apiData = entry.getValue();
String name = apiData.name();
buffer.printf("case %d: // %s%n", apiKey, MessageGenerator.capitalizeFirst(name));
buffer.incrementIndent(); buffer.incrementIndent();
if (type.equals("response") && apiKey == 18) { if (type.equals("response") && apiKey == 18) {
// ApiVersionsResponse always includes a v0 header. buffer.printf("// ApiVersionsResponse always includes a v0 header.%n");
// See KIP-511 for details. buffer.printf("// See KIP-511 for details.%n");
buffer.printf("return (short) 0;%n"); buffer.printf("return (short) 0;%n");
buffer.decrementIndent(); buffer.decrementIndent();
continue; continue;
} }
if (type.equals("request") && apiKey == 7) { if (type.equals("request") && apiKey == 7) {
// Version 0 of ControlledShutdownRequest has a non-standard request header buffer.printf("// Version 0 of ControlledShutdownRequest has a non-standard request header%n");
// which does not include clientId. Version 1 of ControlledShutdownRequest buffer.printf("// which does not include clientId. Version 1 of ControlledShutdownRequest%n");
// and later use the standard request header. buffer.printf("// and later use the standard request header.%n");
buffer.printf("if (_version == 0) {%n"); buffer.printf("if (_version == 0) {%n");
buffer.incrementIndent(); buffer.incrementIndent();
buffer.printf("return (short) 0;%n"); buffer.printf("return (short) 0;%n");