19
19
package org .neo4j .driver .internal .messaging ;
20
20
21
21
import java .io .IOException ;
22
- import java .util .ArrayList ;
23
- import java .util .List ;
24
22
25
- import org .neo4j .driver .internal .InternalCoordinate ;
26
- import org .neo4j .driver .internal .InternalPoint ;
23
+ import org .neo4j .driver .internal .InternalPoint2D ;
24
+ import org .neo4j .driver .internal .InternalPoint3D ;
27
25
import org .neo4j .driver .internal .packstream .PackInput ;
28
26
import org .neo4j .driver .internal .packstream .PackOutput ;
29
27
import org .neo4j .driver .internal .value .InternalValue ;
30
- import org .neo4j .driver .internal .value .PointValue ;
28
+ import org .neo4j .driver .internal .value .Point2DValue ;
29
+ import org .neo4j .driver .internal .value .Point3DValue ;
31
30
import org .neo4j .driver .v1 .Value ;
32
- import org .neo4j .driver .v1 .types .Point ;
31
+ import org .neo4j .driver .v1 .types .Point2D ;
32
+ import org .neo4j .driver .v1 .types .Point3D ;
33
33
34
- import static org .neo4j .driver .internal .types .TypeConstructor .POINT_TyCon ;
34
+ import static org .neo4j .driver .internal .types .TypeConstructor .POINT_2D_TyCon ;
35
+ import static org .neo4j .driver .internal .types .TypeConstructor .POINT_3D_TyCon ;
35
36
36
37
public class PackStreamMessageFormatV2 extends PackStreamMessageFormatV1
37
38
{
38
- private static final byte POINT_STRUCT_TYPE = 'X' ;
39
- private static final int POINT_STRUCT_SIZE = 3 ;
39
+ private static final byte POINT_2D_STRUCT_TYPE = 'X' ;
40
+ private static final byte POINT_3D_STRUCT_TYPE = 'Y' ;
41
+ private static final int POINT_STRUCT_SIZE = 2 ;
40
42
41
43
@ Override
42
44
public MessageFormat .Writer newWriter ( PackOutput output , boolean byteArraySupportEnabled )
@@ -64,22 +66,32 @@ private static class WriterV2 extends WriterV1
64
66
@ Override
65
67
void packInternalValue ( InternalValue value ) throws IOException
66
68
{
67
- if ( value .typeConstructor () == POINT_TyCon )
69
+ if ( value .typeConstructor () == POINT_2D_TyCon )
68
70
{
69
- packPoint ( value .asPoint () );
71
+ packPoint2D ( value .asPoint2D () );
72
+ }
73
+ else if ( value .typeConstructor () == POINT_3D_TyCon )
74
+ {
75
+ packPoint3D ( value .asPoint3D () );
70
76
}
71
77
else
72
78
{
73
79
super .packInternalValue ( value );
74
80
}
75
81
}
76
82
77
- private void packPoint ( Point point ) throws IOException
83
+ private void packPoint2D ( Point2D point ) throws IOException
84
+ {
85
+ packer .packStructHeader ( POINT_STRUCT_SIZE , POINT_2D_STRUCT_TYPE );
86
+ packer .pack ( point .srid () );
87
+ // packer.pack( point.x(), point.y() );
88
+ }
89
+
90
+ private void packPoint3D ( Point3D point ) throws IOException
78
91
{
79
- packer .packStructHeader ( POINT_STRUCT_SIZE , POINT_STRUCT_TYPE );
80
- packer .pack ( point .crsTableId () );
81
- packer .pack ( point .crsCode () );
82
- packer .pack ( point .coordinate ().values () );
92
+ packer .packStructHeader ( POINT_STRUCT_SIZE , POINT_3D_STRUCT_TYPE );
93
+ packer .pack ( point .srid () );
94
+ // packer.pack( point.x(), point.y(), point.z() );
83
95
}
84
96
}
85
97
@@ -93,31 +105,32 @@ private static class ReaderV2 extends ReaderV1
93
105
@ Override
94
106
Value unpackStruct ( long size , byte type ) throws IOException
95
107
{
96
- if ( type == POINT_STRUCT_TYPE )
108
+ if ( type == POINT_2D_STRUCT_TYPE )
109
+ {
110
+ ensureCorrectStructSize ( POINT_2D_TyCon .typeName (), POINT_STRUCT_SIZE , size );
111
+ return unpackPoint2D ();
112
+ }
113
+ else if ( type == POINT_3D_STRUCT_TYPE )
97
114
{
98
- ensureCorrectStructSize ( POINT_TyCon .typeName (), POINT_STRUCT_SIZE , size );
99
- return unpackPoint ();
115
+ ensureCorrectStructSize ( POINT_3D_TyCon .typeName (), POINT_STRUCT_SIZE , size );
116
+ return unpackPoint3D ();
100
117
}
101
118
else
102
119
{
103
120
return super .unpackStruct ( size , type );
104
121
}
105
122
}
106
123
107
- private Value unpackPoint () throws IOException
124
+ private Value unpackPoint2D () throws IOException
108
125
{
109
- long crsTableId = unpacker .unpackLong ();
110
- long crsCode = unpacker .unpackLong ();
111
-
112
- int coordinateSize = (int ) unpacker .unpackListHeader ();
113
- List <Double > coordinate = new ArrayList <>( coordinateSize );
114
- for ( int i = 0 ; i < coordinateSize ; i ++ )
115
- {
116
- coordinate .add ( unpacker .unpackDouble () );
117
- }
126
+ long srid = unpacker .unpackLong ();
127
+ return new Point2DValue ( new InternalPoint2D ( srid , 0.0 , 0.0 ) );
128
+ }
118
129
119
- Point point = new InternalPoint ( crsTableId , crsCode , new InternalCoordinate ( coordinate ) );
120
- return new PointValue ( point );
130
+ private Value unpackPoint3D () throws IOException
131
+ {
132
+ long srid = unpacker .unpackLong ();
133
+ return new Point3DValue ( new InternalPoint3D ( srid , 0.0 , 0.0 , 0.0 ) );
121
134
}
122
135
}
123
136
}
0 commit comments