Skip to content

Commit

Permalink
Add GeoPoint in StreamInput/StreamOutput
Browse files Browse the repository at this point in the history
Closes #13340
  • Loading branch information
Clément Tourrière committed Sep 17, 2015
1 parent 1a8495d commit cc0f8c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Expand Up @@ -31,6 +31,7 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.text.StringAndBytesText;
import org.elasticsearch.common.text.Text;
import org.joda.time.DateTime;
Expand Down Expand Up @@ -420,11 +421,17 @@ public Object readGenericValue() throws IOException {
return readDoubleArray();
case 21:
return readBytesRef();
case 22:
return readGeoPoint();
default:
throw new IOException("Can't read unknown type [" + type + "]");
}
}

public GeoPoint readGeoPoint() throws IOException {
return new GeoPoint(readDouble(), readDouble());
}

public int[] readIntArray() throws IOException {
int length = readVInt();
int[] values = new int[length];
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.text.Text;
import org.joda.time.ReadableInstant;

Expand Down Expand Up @@ -408,6 +409,10 @@ public void writeGenericValue(@Nullable Object value) throws IOException {
} else if (value instanceof BytesRef) {
writeByte((byte) 21);
writeBytesRef((BytesRef) value);
} else if (type == GeoPoint.class) {
writeByte((byte) 22);
writeDouble(((GeoPoint) value).lat());
writeDouble(((GeoPoint) value).lon());
} else {
throw new IOException("Can't write type [" + type + "]");
}
Expand Down

0 comments on commit cc0f8c2

Please sign in to comment.