Add GeoPoint in StreamInput/StreamOutput

Closes #13340
This commit is contained in:
Clément Tourrière 2015-09-17 14:56:24 +02:00
parent 1a8495d1d6
commit cc0f8c2eb1
2 changed files with 12 additions and 0 deletions

View File

@ -31,6 +31,7 @@ import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.text.StringAndBytesText; import org.elasticsearch.common.text.StringAndBytesText;
import org.elasticsearch.common.text.Text; import org.elasticsearch.common.text.Text;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -420,11 +421,17 @@ public abstract class StreamInput extends InputStream {
return readDoubleArray(); return readDoubleArray();
case 21: case 21:
return readBytesRef(); return readBytesRef();
case 22:
return readGeoPoint();
default: default:
throw new IOException("Can't read unknown type [" + type + "]"); throw new IOException("Can't read unknown type [" + type + "]");
} }
} }
public GeoPoint readGeoPoint() throws IOException {
return new GeoPoint(readDouble(), readDouble());
}
public int[] readIntArray() throws IOException { public int[] readIntArray() throws IOException {
int length = readVInt(); int length = readVInt();
int[] values = new int[length]; int[] values = new int[length];

View File

@ -30,6 +30,7 @@ import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.text.Text; import org.elasticsearch.common.text.Text;
import org.joda.time.ReadableInstant; import org.joda.time.ReadableInstant;
@ -408,6 +409,10 @@ public abstract class StreamOutput extends OutputStream {
} else if (value instanceof BytesRef) { } else if (value instanceof BytesRef) {
writeByte((byte) 21); writeByte((byte) 21);
writeBytesRef((BytesRef) value); writeBytesRef((BytesRef) value);
} else if (type == GeoPoint.class) {
writeByte((byte) 22);
writeDouble(((GeoPoint) value).lat());
writeDouble(((GeoPoint) value).lon());
} else { } else {
throw new IOException("Can't write type [" + type + "]"); throw new IOException("Can't write type [" + type + "]");
} }