Skip to content

Commit

Permalink
Serialize MediaType as an integer to avoid string parsing
Browse files Browse the repository at this point in the history
Resolves opensearch-project#15979

Signed-off-by: Andrew Ross <[email protected]>
  • Loading branch information
andrross committed Sep 18, 2024
1 parent bd090d8 commit 32a55c7
Showing 1 changed file with 1 addition and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@
import com.fasterxml.jackson.dataformat.cbor.CBORConstants;
import com.fasterxml.jackson.dataformat.smile.SmileConstants;

import org.opensearch.Version;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.common.xcontent.cbor.CborXContent;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.common.xcontent.smile.SmileXContent;
import org.opensearch.common.xcontent.yaml.YamlXContent;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.core.xcontent.XContent;
import org.opensearch.core.xcontent.XContentBuilder;
Expand Down Expand Up @@ -239,7 +237,7 @@ public XContentBuilder contentBuilder(final OutputStream os) throws IOException
}
};

private int index;
private final int index;

XContentType(int index) {
this.index = index;
Expand All @@ -259,15 +257,6 @@ public String format() {
return subtype();
}

@Override
public void writeTo(StreamOutput output) throws IOException {
if (output.getVersion().onOrAfter(Version.V_3_0_0)) {
output.writeVInt(uniqueId());
} else {
output.writeString(this.mediaType());
}
}

@Override
public int uniqueId() {
return this.ordinal();
Expand Down

0 comments on commit 32a55c7

Please sign in to comment.