Decouple XContentType from StreamInput/Output (elastic/x-pack-elasticsearch#4065)

This removes the readFrom and writeTo methods from XContentType, instead using
the more generic `readEnum` and `writeEnum` methods. Luckily they are both
encoded exactly the same way, so there is no compatibility layer needed for
backwards compatibility.

This is the x-pack side of https://github.com/elastic/elasticsearch/pull/28927

Original commit: elastic/x-pack-elasticsearch@f1c0928490
This commit is contained in:
Lee Hinman 2018-03-07 14:50:33 -07:00 committed by GitHub
parent 39c1dd085a
commit 2ecce78b13
6 changed files with 11 additions and 11 deletions

View File

@ -178,7 +178,7 @@ public class PostDataAction extends Action<PostDataAction.Request, PostDataActio
dataDescription = in.readOptionalWriteable(DataDescription::new);
content = in.readBytesReference();
if (in.readBoolean()) {
xContentType = XContentType.readFrom(in);
xContentType = in.readEnum(XContentType.class);
}
}
@ -192,7 +192,7 @@ public class PostDataAction extends Action<PostDataAction.Request, PostDataActio
boolean hasXContentType = xContentType != null;
out.writeBoolean(hasXContentType);
if (hasXContentType) {
xContentType.writeTo(out);
out.writeEnum(xContentType);
}
}

View File

@ -70,7 +70,7 @@ public class MonitoringBulkDoc implements Writeable {
final String type = in.readOptionalString();
final String id = in.readOptionalString();
final BytesReference source = in.readBytesReference();
final XContentType xContentType = (source != BytesArray.EMPTY) ? XContentType.readFrom(in) : XContentType.JSON;
final XContentType xContentType = (source != BytesArray.EMPTY) ? in.readEnum(XContentType.class) : XContentType.JSON;
long interval = 0L;
if (in.getVersion().onOrAfter(Version.V_6_0_0_rc1)) {
@ -95,7 +95,7 @@ public class MonitoringBulkDoc implements Writeable {
out.writeOptionalString(id);
out.writeBytesReference(source);
if (source != BytesArray.EMPTY) {
xContentType.writeTo(out);
out.writeEnum(xContentType);
}
if (out.getVersion().onOrAfter(Version.V_6_0_0_rc1)) {
out.writeVLong(intervalMillis);

View File

@ -293,7 +293,7 @@ public class WatcherXContentParser implements XContentParser {
}
@Override
public void close() throws ElasticsearchException {
public void close() throws IOException {
parser.close();
}

View File

@ -112,12 +112,12 @@ public class XContentSource implements ToXContent {
}
public static XContentSource readFrom(StreamInput in) throws IOException {
return new XContentSource(in.readBytesReference(), XContentType.readFrom(in));
return new XContentSource(in.readBytesReference(), in.readEnum(XContentType.class));
}
public static void writeTo(XContentSource source, StreamOutput out) throws IOException {
out.writeBytesReference(source.bytes);
source.contentType.writeTo(out);
out.writeEnum(source.contentType);
}
private Object data() {

View File

@ -69,7 +69,7 @@ public class ExecuteWatchRequest extends ActionRequest {
}
if (in.readBoolean()) {
watchSource = in.readBytesReference();
xContentType = XContentType.readFrom(in);
xContentType = in.readEnum(XContentType.class);
}
debug = in.readBoolean();
}
@ -96,7 +96,7 @@ public class ExecuteWatchRequest extends ActionRequest {
out.writeBoolean(watchSource != null);
if (watchSource != null) {
out.writeBytesReference(watchSource);
xContentType.writeTo(out);
out.writeEnum(xContentType);
}
out.writeBoolean(debug);
}

View File

@ -45,7 +45,7 @@ public class PutWatchRequest extends ActionRequest {
id = in.readString();
source = in.readBytesReference();
active = in.readBoolean();
xContentType = XContentType.readFrom(in);
xContentType = in.readEnum(XContentType.class);
version = in.readZLong();
}
@ -55,7 +55,7 @@ public class PutWatchRequest extends ActionRequest {
out.writeString(id);
out.writeBytesReference(source);
out.writeBoolean(active);
xContentType.writeTo(out);
out.writeEnum(xContentType);
out.writeZLong(version);
}