Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced an extension of Bolt V1 with one additional type - point. New protocol version is exactly the same as the previous one but is able to serialize/deserialize points. Arbitrary dimensional points are supported. Serialization format is generic and allows `double[]` array as point coordinate. Made protocol test utilities able to work with different protocol versions.
- Loading branch information
Showing
33 changed files
with
934 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
community/bolt/src/main/java/org/neo4j/bolt/v2/messaging/Neo4jPackV2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.bolt.v2.messaging; | ||
|
||
import java.io.IOException; | ||
|
||
import org.neo4j.bolt.v1.messaging.Neo4jPack; | ||
import org.neo4j.bolt.v1.messaging.Neo4jPackV1; | ||
import org.neo4j.bolt.v1.packstream.PackInput; | ||
import org.neo4j.bolt.v1.packstream.PackOutput; | ||
import org.neo4j.values.AnyValue; | ||
import org.neo4j.values.storable.CoordinateReferenceSystem; | ||
import org.neo4j.values.storable.PointValue; | ||
|
||
import static org.neo4j.values.storable.Values.doubleArray; | ||
import static org.neo4j.values.storable.Values.pointValue; | ||
|
||
public class Neo4jPackV2 extends Neo4jPackV1 | ||
{ | ||
public static final byte POINT = 'X'; | ||
|
||
@Override | ||
public Neo4jPack.Packer newPacker( PackOutput output ) | ||
{ | ||
return new PackerV2( output ); | ||
} | ||
|
||
@Override | ||
public Neo4jPack.Unpacker newUnpacker( PackInput input ) | ||
{ | ||
return new UnpackerV2( input ); | ||
} | ||
|
||
private static class PackerV2 extends Neo4jPackV1.PackerV1 | ||
{ | ||
PackerV2( PackOutput output ) | ||
{ | ||
super( output ); | ||
} | ||
|
||
@Override | ||
public void writePoint( CoordinateReferenceSystem crs, double[] coordinate ) throws IOException | ||
{ | ||
packStructHeader( 3, POINT ); | ||
pack( crs.getTable().getTableId() ); | ||
pack( crs.getCode() ); | ||
pack( doubleArray( coordinate ) ); | ||
} | ||
} | ||
|
||
private static class UnpackerV2 extends Neo4jPackV1.UnpackerV1 | ||
{ | ||
UnpackerV2( PackInput input ) | ||
{ | ||
super( input ); | ||
} | ||
|
||
@Override | ||
protected AnyValue unpackStruct( char signature ) throws IOException | ||
{ | ||
if ( signature == POINT ) | ||
{ | ||
return unpackPoint(); | ||
} | ||
return super.unpackStruct( signature ); | ||
} | ||
|
||
private PointValue unpackPoint() throws IOException | ||
{ | ||
int tableId = unpackInteger(); | ||
int code = unpackInteger(); | ||
CoordinateReferenceSystem crs = CoordinateReferenceSystem.get( tableId, code ); | ||
int length = (int) unpackListHeader(); | ||
double[] coordinates = new double[length]; | ||
for ( int i = 0; i < length; i++ ) | ||
{ | ||
coordinates[i] = unpackDouble(); | ||
} | ||
return pointValue( crs, coordinates ); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
community/bolt/src/main/java/org/neo4j/bolt/v2/transport/BoltMessagingProtocolV2Handler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.bolt.v2.transport; | ||
|
||
import org.neo4j.bolt.BoltChannel; | ||
import org.neo4j.bolt.transport.TransportThrottleGroup; | ||
import org.neo4j.bolt.v1.runtime.BoltWorker; | ||
import org.neo4j.bolt.v1.transport.BoltMessagingProtocolV1Handler; | ||
import org.neo4j.bolt.v2.messaging.Neo4jPackV2; | ||
import org.neo4j.kernel.impl.logging.LogService; | ||
|
||
public class BoltMessagingProtocolV2Handler extends BoltMessagingProtocolV1Handler | ||
{ | ||
public static final int VERSION = 2; | ||
|
||
public BoltMessagingProtocolV2Handler( BoltChannel boltChannel, BoltWorker worker, | ||
TransportThrottleGroup throttleGroup, LogService logging ) | ||
{ | ||
super( boltChannel, worker, new Neo4jPackV2(), throttleGroup, logging ); | ||
} | ||
|
||
@Override | ||
public int version() | ||
{ | ||
return VERSION; | ||
} | ||
} |
Oops, something went wrong.