25
25
import java .util .List ;
26
26
import java .util .Map ;
27
27
28
- import org .neo4j .driver .Value ;
29
-
30
28
import static java .lang .Integer .toHexString ;
31
29
import static java .lang .String .format ;
32
30
import static java .util .Arrays .asList ;
44
42
* <table>
45
43
* <tr><th>Marker</th><th>Binary</th><th>Type</th><th>Description</th></tr>
46
44
* <tr><td><code>00..7F</code></td><td><code>0xxxxxxx</code></td><td>+TINY_INT</td><td>Integer 0 to 127</td></tr>
47
- * <tr><td><code>80..8F</code></td><td><code>1000xxxx</code></td><td>TINY_TEXT </td><td></td></tr>
45
+ * <tr><td><code>80..8F</code></td><td><code>1000xxxx</code></td><td>TINY_STRING </td><td></td></tr>
48
46
* <tr><td><code>90..9F</code></td><td><code>1001xxxx</code></td><td>TINY_LIST</td><td></td></tr>
49
47
* <tr><td><code>A0..AF</code></td><td><code>1010xxxx</code></td><td>TINY_MAP</td><td></td></tr>
50
48
* <tr><td><code>B0..BF</code></td><td><code>1011xxxx</code></td><td>TINY_STRUCT</td><td></td></tr>
61
59
* <tr><td><code>CD</code></td><td><code>11001101</code></td><td>BYTES_16</td><td>Byte string (fewer than 2<sup>16</sup> bytes)</td></tr>
62
60
* <tr><td><code>CE</code></td><td><code>11001110</code></td><td>BYTES_32</td><td>Byte string (fewer than 2<sup>32</sup> bytes)</td></tr>
63
61
* <tr><td><code>CF</code></td><td><code>11001111</code></td><td><em>RESERVED</em></td><td></td></tr>
64
- * <tr><td><code>D0</code></td><td><code>11010000</code></td><td>TEXT_8 </td><td>UTF-8 encoded text string (fewer than 2<sup>8</sup> bytes)</td></tr>
65
- * <tr><td><code>D1</code></td><td><code>11010001</code></td><td>TEXT_16 </td><td>UTF-8 encoded text string (fewer than 2<sup>16</sup> bytes)</td></tr>
66
- * <tr><td><code>D2</code></td><td><code>11010010</code></td><td>TEXT_32 </td><td>UTF-8 encoded text string (fewer than 2<sup>32</sup> bytes)</td></tr>
62
+ * <tr><td><code>D0</code></td><td><code>11010000</code></td><td>STRING_8 </td><td>UTF-8 encoded string (fewer than 2<sup>8</sup> bytes)</td></tr>
63
+ * <tr><td><code>D1</code></td><td><code>11010001</code></td><td>STRING_16 </td><td>UTF-8 encoded string (fewer than 2<sup>16</sup> bytes)</td></tr>
64
+ * <tr><td><code>D2</code></td><td><code>11010010</code></td><td>STRING_32 </td><td>UTF-8 encoded string (fewer than 2<sup>32</sup> bytes)</td></tr>
67
65
* <tr><td><code>D3</code></td><td><code>11010011</code></td><td><em>RESERVED</em></td><td></td></tr>
68
66
* <tr><td><code>D4</code></td><td><code>11010100</code></td><td>LIST_8</td><td>List (fewer than 2<sup>8</sup> items)</td></tr>
69
67
* <tr><td><code>D5</code></td><td><code>11010101</code></td><td>LIST_16</td><td>List (fewer than 2<sup>16</sup> items)</td></tr>
85
83
public class PackStream
86
84
{
87
85
88
- public static final byte TINY_TEXT = (byte ) 0x80 ;
86
+ public static final byte TINY_STRING = (byte ) 0x80 ;
89
87
public static final byte TINY_LIST = (byte ) 0x90 ;
90
88
public static final byte TINY_MAP = (byte ) 0xA0 ;
91
89
public static final byte TINY_STRUCT = (byte ) 0xB0 ;
@@ -105,9 +103,9 @@ public class PackStream
105
103
public static final byte BYTES_16 = (byte ) 0xCD ;
106
104
public static final byte BYTES_32 = (byte ) 0xCE ;
107
105
public static final byte RESERVED_CF = (byte ) 0xCF ;
108
- public static final byte TEXT_8 = (byte ) 0xD0 ;
109
- public static final byte TEXT_16 = (byte ) 0xD1 ;
110
- public static final byte TEXT_32 = (byte ) 0xD2 ;
106
+ public static final byte STRING_8 = (byte ) 0xD0 ;
107
+ public static final byte STRING_16 = (byte ) 0xD1 ;
108
+ public static final byte STRING_32 = (byte ) 0xD2 ;
111
109
public static final byte RESERVED_D3 = (byte ) 0xD3 ;
112
110
public static final byte LIST_8 = (byte ) 0xD4 ;
113
111
public static final byte LIST_16 = (byte ) 0xD5 ;
@@ -242,17 +240,17 @@ public void pack( String value ) throws IOException
242
240
else
243
241
{
244
242
byte [] utf8 = value .getBytes ( UTF_8 );
245
- packTextHeader ( utf8 .length );
243
+ packStringHeader ( utf8 .length );
246
244
packRaw ( utf8 );
247
245
}
248
246
}
249
247
250
- public void packText ( byte [] utf8 ) throws IOException
248
+ public void packString ( byte [] utf8 ) throws IOException
251
249
{
252
250
if ( utf8 == null ) { packNull (); }
253
251
else
254
252
{
255
- packTextHeader ( utf8 .length );
253
+ packStringHeader ( utf8 .length );
256
254
packRaw ( utf8 );
257
255
}
258
256
}
@@ -329,25 +327,25 @@ else if ( size <= Short.MAX_VALUE )
329
327
}
330
328
}
331
329
332
- public void packTextHeader ( int size ) throws IOException
330
+ public void packStringHeader ( int size ) throws IOException
333
331
{
334
332
if ( size < 0x10 )
335
333
{
336
- out .writeByte ( (byte ) (TINY_TEXT | size ) );
334
+ out .writeByte ( (byte ) (TINY_STRING | size ) );
337
335
}
338
336
else if ( size <= Byte .MAX_VALUE )
339
337
{
340
- out .writeByte ( TEXT_8 )
338
+ out .writeByte ( STRING_8 )
341
339
.writeByte ( (byte ) size );
342
340
}
343
341
else if ( size <= Short .MAX_VALUE )
344
342
{
345
- out .writeByte ( TEXT_16 )
343
+ out .writeByte ( STRING_16 )
346
344
.writeShort ( (short ) size );
347
345
}
348
346
else
349
347
{
350
- out .writeByte ( TEXT_32 )
348
+ out .writeByte ( STRING_32 )
351
349
.writeInt ( size );
352
350
}
353
351
}
@@ -537,7 +535,7 @@ public double unpackDouble() throws IOException
537
535
public String unpackString () throws IOException
538
536
{
539
537
final byte markerByte = in .readByte ();
540
- if ( markerByte == TINY_TEXT ) // Note no mask, so we compare to 0x80.
538
+ if ( markerByte == TINY_STRING ) // Note no mask, so we compare to 0x80.
541
539
{
542
540
return EMPTY_STRING ;
543
541
}
@@ -591,12 +589,12 @@ private byte[] unpackUtf8(byte markerByte) throws IOException
591
589
final byte markerHighNibble = (byte ) (markerByte & 0xF0 );
592
590
final byte markerLowNibble = (byte ) (markerByte & 0x0F );
593
591
594
- if ( markerHighNibble == TINY_TEXT ) { return unpackBytes ( markerLowNibble ); }
592
+ if ( markerHighNibble == TINY_STRING ) { return unpackBytes ( markerLowNibble ); }
595
593
switch (markerByte )
596
594
{
597
- case TEXT_8 : return unpackBytes ( unpackUINT8 () );
598
- case TEXT_16 : return unpackBytes ( unpackUINT16 () );
599
- case TEXT_32 :
595
+ case STRING_8 : return unpackBytes ( unpackUINT8 () );
596
+ case STRING_16 : return unpackBytes ( unpackUINT16 () );
597
+ case STRING_32 :
600
598
{
601
599
long size = unpackUINT32 ();
602
600
if ( size <= Integer .MAX_VALUE )
@@ -605,7 +603,7 @@ private byte[] unpackUtf8(byte markerByte) throws IOException
605
603
}
606
604
else
607
605
{
608
- throw new Overflow ( "TEXT_32 too long for Java" );
606
+ throw new Overflow ( "STRING_32 too long for Java" );
609
607
}
610
608
}
611
609
default : throw new Unexpected ( "Expected a string, but got: 0x" + toHexString ( markerByte & 0xFF ));
@@ -655,7 +653,7 @@ public PackType peekNextType() throws IOException
655
653
656
654
switch (markerHighNibble )
657
655
{
658
- case TINY_TEXT : return PackType .TEXT ;
656
+ case TINY_STRING : return PackType .STRING ;
659
657
case TINY_LIST : return PackType .LIST ;
660
658
case TINY_MAP : return PackType .MAP ;
661
659
case TINY_STRUCT : return PackType .STRUCT ;
@@ -674,10 +672,10 @@ public PackType peekNextType() throws IOException
674
672
case BYTES_16 :
675
673
case BYTES_32 :
676
674
return PackType .BYTES ;
677
- case TEXT_8 :
678
- case TEXT_16 :
679
- case TEXT_32 :
680
- return PackType .TEXT ;
675
+ case STRING_8 :
676
+ case STRING_16 :
677
+ case STRING_32 :
678
+ return PackType .STRING ;
681
679
case LIST_8 :
682
680
case LIST_16 :
683
681
case LIST_32 :
0 commit comments