Switch to StreamInput.readEnum and StreamOutput.writeEnum (elastic/x-pack-elasticsearch#1313)
Start using StreamInput.readEnum and StreamOutput.writeEnum for enum serialization. Relates to elastic/elasticsearch#24475 Original commit: elastic/x-pack-elasticsearch@67ca571458
This commit is contained in:
parent
9e3d5d6cf3
commit
9a800cac60
|
@ -142,16 +142,12 @@ public class ChunkingConfig extends ToXContentToBytes implements Writeable {
|
|||
}
|
||||
|
||||
public static Mode readFromStream(StreamInput in) throws IOException {
|
||||
int ordinal = in.readVInt();
|
||||
if (ordinal < 0 || ordinal >= values().length) {
|
||||
throw new IOException("Unknown Mode ordinal [" + ordinal + "]");
|
||||
}
|
||||
return values()[ordinal];
|
||||
return in.readEnum(Mode.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(ordinal());
|
||||
out.writeEnum(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,11 +37,7 @@ public enum DatafeedState implements Task.Status {
|
|||
}
|
||||
|
||||
public static DatafeedState fromStream(StreamInput in) throws IOException {
|
||||
int ordinal = in.readVInt();
|
||||
if (ordinal < 0 || ordinal >= values().length) {
|
||||
throw new IOException("Unknown public enum DatafeedState ordinal [" + ordinal + "]");
|
||||
}
|
||||
return values()[ordinal];
|
||||
return in.readEnum(DatafeedState.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,7 +47,7 @@ public enum DatafeedState implements Task.Status {
|
|||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(ordinal());
|
||||
out.writeEnum(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,16 +27,12 @@ public enum Connective implements Writeable {
|
|||
}
|
||||
|
||||
public static Connective readFromStream(StreamInput in) throws IOException {
|
||||
int ordinal = in.readVInt();
|
||||
if (ordinal < 0 || ordinal >= values().length) {
|
||||
throw new IOException("Unknown Connective ordinal [" + ordinal + "]");
|
||||
}
|
||||
return values()[ordinal];
|
||||
return in.readEnum(Connective.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(ordinal());
|
||||
out.writeEnum(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -63,16 +63,12 @@ public class DataDescription extends ToXContentToBytes implements Writeable {
|
|||
}
|
||||
|
||||
public static DataFormat readFromStream(StreamInput in) throws IOException {
|
||||
int ordinal = in.readVInt();
|
||||
if (ordinal < 0 || ordinal >= values().length) {
|
||||
throw new IOException("Unknown DataFormat ordinal [" + ordinal + "]");
|
||||
}
|
||||
return values()[ordinal];
|
||||
return in.readEnum(DataFormat.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(ordinal());
|
||||
out.writeEnum(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -54,16 +54,12 @@ public class Detector extends ToXContentToBytes implements Writeable {
|
|||
}
|
||||
|
||||
public static ExcludeFrequent readFromStream(StreamInput in) throws IOException {
|
||||
int ordinal = in.readVInt();
|
||||
if (ordinal < 0 || ordinal >= values().length) {
|
||||
throw new IOException("Unknown ExcludeFrequent ordinal [" + ordinal + "]");
|
||||
}
|
||||
return values()[ordinal];
|
||||
return in.readEnum(ExcludeFrequent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(ordinal());
|
||||
out.writeEnum(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,16 +29,12 @@ public enum JobState implements ToXContent, Writeable {
|
|||
}
|
||||
|
||||
public static JobState fromStream(StreamInput in) throws IOException {
|
||||
int ordinal = in.readVInt();
|
||||
if (ordinal < 0 || ordinal >= values().length) {
|
||||
throw new IOException("Unknown public enum JobState {\n ordinal [" + ordinal + "]");
|
||||
}
|
||||
return values()[ordinal];
|
||||
return in.readEnum(JobState.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(ordinal());
|
||||
out.writeEnum(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -84,16 +84,12 @@ public enum Operator implements Writeable {
|
|||
}
|
||||
|
||||
public static Operator readFromStream(StreamInput in) throws IOException {
|
||||
int ordinal = in.readVInt();
|
||||
if (ordinal < 0 || ordinal >= values().length) {
|
||||
throw new IOException("Unknown Operator ordinal [" + ordinal + "]");
|
||||
}
|
||||
return values()[ordinal];
|
||||
return in.readEnum(Operator.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(ordinal());
|
||||
out.writeEnum(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,16 +26,12 @@ public enum RuleAction implements Writeable {
|
|||
}
|
||||
|
||||
public static RuleAction readFromStream(StreamInput in) throws IOException {
|
||||
int ordinal = in.readVInt();
|
||||
if (ordinal < 0 || ordinal >= values().length) {
|
||||
throw new IOException("Unknown RuleAction ordinal [" + ordinal + "]");
|
||||
}
|
||||
return values()[ordinal];
|
||||
return in.readEnum(RuleAction.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(ordinal());
|
||||
out.writeEnum(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,16 +31,12 @@ public enum RuleConditionType implements Writeable {
|
|||
}
|
||||
|
||||
public static RuleConditionType readFromStream(StreamInput in) throws IOException {
|
||||
int ordinal = in.readVInt();
|
||||
if (ordinal < 0 || ordinal >= values().length) {
|
||||
throw new IOException("Unknown RuleConditionType ordinal [" + ordinal + "]");
|
||||
}
|
||||
return values()[ordinal];
|
||||
return in.readEnum(RuleConditionType.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(ordinal());
|
||||
out.writeEnum(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -96,16 +96,12 @@ public class ModelSizeStats extends ToXContentToBytes implements Writeable {
|
|||
}
|
||||
|
||||
public static MemoryStatus readFromStream(StreamInput in) throws IOException {
|
||||
int ordinal = in.readVInt();
|
||||
if (ordinal < 0 || ordinal >= values().length) {
|
||||
throw new IOException("Unknown MemoryStatus ordinal [" + ordinal + "]");
|
||||
}
|
||||
return values()[ordinal];
|
||||
return in.readEnum(MemoryStatus.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(ordinal());
|
||||
out.writeEnum(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,16 +27,12 @@ public enum Level implements Writeable {
|
|||
}
|
||||
|
||||
public static Level readFromStream(StreamInput in) throws IOException {
|
||||
int ordinal = in.readVInt();
|
||||
if (ordinal < 0 || ordinal >= values().length) {
|
||||
throw new IOException("Unknown Level ordinal [" + ordinal + "]");
|
||||
}
|
||||
return values()[ordinal];
|
||||
return in.readEnum(Level.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(ordinal());
|
||||
out.writeEnum(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue