Skip to content

Commit dde6fb8

Browse files
committed
Added pack stream V2 with float pair and triple
Made 2D and 3D points use these new types. Refactored `PackStream` into a separate packer and unpacker. They are now top-level classes and exist for V1 and V2 pack stream versions. Later adds FLOAT_PAIR and FLOAT_TRIPLE types. Turned pack stream exceptions into top-level classes and moved them to a dedicated package.
1 parent 03e4542 commit dde6fb8

File tree

21 files changed

+1088
-725
lines changed

21 files changed

+1088
-725
lines changed

driver/src/main/java/org/neo4j/driver/internal/async/inbound/ByteBufInput.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,9 @@ public double readDouble()
7070
}
7171

7272
@Override
73-
public PackInput readBytes( byte[] into, int offset, int toRead )
73+
public void readBytes( byte[] into, int offset, int toRead )
7474
{
7575
buf.readBytes( into, offset, toRead );
76-
return this;
7776
}
7877

7978
@Override

driver/src/main/java/org/neo4j/driver/internal/messaging/PackStreamMessageFormatV1.java

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
import org.neo4j.driver.internal.InternalNode;
2929
import org.neo4j.driver.internal.InternalPath;
3030
import org.neo4j.driver.internal.InternalRelationship;
31-
import org.neo4j.driver.internal.packstream.ByteArrayIncompatiblePacker;
3231
import org.neo4j.driver.internal.packstream.PackInput;
3332
import org.neo4j.driver.internal.packstream.PackOutput;
34-
import org.neo4j.driver.internal.packstream.PackStream;
3533
import org.neo4j.driver.internal.packstream.PackType;
34+
import org.neo4j.driver.internal.packstream.PackerV1;
35+
import org.neo4j.driver.internal.packstream.UnpackerV1;
3636
import org.neo4j.driver.internal.util.Iterables;
3737
import org.neo4j.driver.internal.value.InternalValue;
3838
import org.neo4j.driver.internal.value.ListValue;
@@ -73,33 +73,22 @@ public class PackStreamMessageFormatV1 implements MessageFormat
7373
@Override
7474
public MessageFormat.Writer newWriter( PackOutput output, boolean byteArraySupportEnabled )
7575
{
76-
return new WriterV1( output, byteArraySupportEnabled );
76+
return new WriterV1( new PackerV1( output, byteArraySupportEnabled ) );
7777
}
7878

7979
@Override
8080
public MessageFormat.Reader newReader( PackInput input )
8181
{
82-
return new ReaderV1( input );
82+
return new ReaderV1( new UnpackerV1( input ) );
8383
}
8484

8585
static class WriterV1 implements MessageFormat.Writer, MessageHandler
8686
{
87-
final PackStream.Packer packer;
87+
private final PackerV1 packer;
8888

89-
/**
90-
* @param output interface to write messages to
91-
* @param byteArraySupportEnabled specify if support to pack/write byte array to server
92-
*/
93-
WriterV1( PackOutput output, boolean byteArraySupportEnabled )
89+
WriterV1( PackerV1 packer )
9490
{
95-
if( byteArraySupportEnabled )
96-
{
97-
packer = new PackStream.Packer( output );
98-
}
99-
else
100-
{
101-
packer = new ByteArrayIncompatiblePacker( output );
102-
}
91+
this.packer = packer;
10392
}
10493

10594
@Override
@@ -362,11 +351,11 @@ private void packProperties( Entity entity ) throws IOException
362351

363352
static class ReaderV1 implements MessageFormat.Reader
364353
{
365-
final PackStream.Unpacker unpacker;
354+
private final UnpackerV1 unpacker;
366355

367-
ReaderV1( PackInput input )
356+
ReaderV1( UnpackerV1 unpacker )
368357
{
369-
unpacker = new PackStream.Unpacker( input );
358+
this.unpacker = unpacker;
370359
}
371360

372361
/**

driver/src/main/java/org/neo4j/driver/internal/messaging/PackStreamMessageFormatV2.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.neo4j.driver.internal.InternalPoint3D;
2525
import org.neo4j.driver.internal.packstream.PackInput;
2626
import org.neo4j.driver.internal.packstream.PackOutput;
27+
import org.neo4j.driver.internal.packstream.PackerV2;
28+
import org.neo4j.driver.internal.packstream.UnpackerV2;
2729
import org.neo4j.driver.internal.value.InternalValue;
2830
import org.neo4j.driver.internal.value.Point2DValue;
2931
import org.neo4j.driver.internal.value.Point3DValue;
@@ -47,20 +49,23 @@ public MessageFormat.Writer newWriter( PackOutput output, boolean byteArraySuppo
4749
{
4850
throw new IllegalArgumentException( "Bolt V2 should support byte arrays" );
4951
}
50-
return new WriterV2( output );
52+
return new WriterV2( new PackerV2( output ) );
5153
}
5254

5355
@Override
5456
public MessageFormat.Reader newReader( PackInput input )
5557
{
56-
return new ReaderV2( input );
58+
return new ReaderV2( new UnpackerV2( input ) );
5759
}
5860

5961
private static class WriterV2 extends WriterV1
6062
{
61-
WriterV2( PackOutput output )
63+
private final PackerV2 packer;
64+
65+
WriterV2( PackerV2 packer )
6266
{
63-
super( output, true );
67+
super( packer );
68+
this.packer = packer;
6469
}
6570

6671
@Override
@@ -84,22 +89,25 @@ private void packPoint2D( Point2D point ) throws IOException
8489
{
8590
packer.packStructHeader( POINT_STRUCT_SIZE, POINT_2D_STRUCT_TYPE );
8691
packer.pack( point.srid() );
87-
// packer.pack( point.x(), point.y() );
92+
packer.pack( point.x(), point.y() );
8893
}
8994

9095
private void packPoint3D( Point3D point ) throws IOException
9196
{
9297
packer.packStructHeader( POINT_STRUCT_SIZE, POINT_3D_STRUCT_TYPE );
9398
packer.pack( point.srid() );
94-
// packer.pack( point.x(), point.y(), point.z() );
99+
packer.pack( point.x(), point.y(), point.z() );
95100
}
96101
}
97102

98103
private static class ReaderV2 extends ReaderV1
99104
{
100-
ReaderV2( PackInput input )
105+
private final UnpackerV2 unpacker;
106+
107+
ReaderV2( UnpackerV2 unpacker )
101108
{
102-
super( input );
109+
super( unpacker );
110+
this.unpacker = unpacker;
103111
}
104112

105113
@Override
@@ -124,13 +132,15 @@ else if ( type == POINT_3D_STRUCT_TYPE )
124132
private Value unpackPoint2D() throws IOException
125133
{
126134
long srid = unpacker.unpackLong();
127-
return new Point2DValue( new InternalPoint2D( srid, 0.0, 0.0 ) );
135+
double[] coordinate = unpacker.unpackDoublePair();
136+
return new Point2DValue( new InternalPoint2D( srid, coordinate[0], coordinate[1] ) );
128137
}
129138

130139
private Value unpackPoint3D() throws IOException
131140
{
132141
long srid = unpacker.unpackLong();
133-
return new Point3DValue( new InternalPoint3D( srid, 0.0, 0.0, 0.0 ) );
142+
double[] coordinate = unpacker.unpackDoubleTriple();
143+
return new Point3DValue( new InternalPoint3D( srid, coordinate[0], coordinate[1], coordinate[2] ) );
134144
}
135145
}
136146
}

driver/src/main/java/org/neo4j/driver/internal/packstream/PackInput.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import java.io.IOException;
2222

2323
/**
24-
* This is what {@link PackStream} uses to ingest data, implement this on top of any data source of your choice to
25-
* deserialize the stream with {@link PackStream}.
24+
* This is what pack stream unpackers use to ingest data, implement this on top of
25+
* any data source of your choice to deserialize the stream.
2626
*/
2727
public interface PackInput
2828
{
@@ -42,7 +42,7 @@ public interface PackInput
4242
double readDouble() throws IOException;
4343

4444
/** Consume a specified number of bytes */
45-
PackInput readBytes( byte[] into, int offset, int toRead ) throws IOException;
45+
void readBytes( byte[] into, int offset, int toRead ) throws IOException;
4646

4747
/** Get the next byte without forwarding the internal pointer */
4848
byte peekByte() throws IOException;

driver/src/main/java/org/neo4j/driver/internal/packstream/PackOutput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.io.IOException;
2222

2323
/**
24-
* This is where {@link PackStream} writes its output to.
24+
* This is where pack stream packers writes output to.
2525
*/
2626
public interface PackOutput
2727
{

0 commit comments

Comments
 (0)