20
20
21
21
package com .arangodb .velocypack ;
22
22
23
- import java .io .UnsupportedEncodingException ;
24
23
import java .math .BigDecimal ;
25
24
import java .math .BigInteger ;
26
25
import java .nio .charset .StandardCharsets ;
27
26
import java .sql .Timestamp ;
28
27
import java .util .ArrayList ;
29
28
import java .util .Arrays ;
30
29
import java .util .Collection ;
31
- import java .util .Collections ;
32
30
import java .util .Comparator ;
33
31
import java .util .Date ;
34
- import java .util .HashMap ;
35
32
import java .util .List ;
36
- import java .util .Map ;
37
33
38
34
import com .arangodb .velocypack .exception .VPackBuilderException ;
39
35
import com .arangodb .velocypack .exception .VPackBuilderKeyAlreadyWrittenException ;
47
43
import com .arangodb .velocypack .internal .DefaultVPackBuilderOptions ;
48
44
import com .arangodb .velocypack .internal .Value ;
49
45
import com .arangodb .velocypack .internal .util .NumberUtil ;
50
- import com .fasterxml .jackson .core .io .CharTypes ;
51
46
52
47
/**
53
48
* @author Mark Vollmary
@@ -271,6 +266,18 @@ private void ensureCapacity(final int minCapacity) {
271
266
}
272
267
}
273
268
269
+ private void appendTag (long tag ) {
270
+ if (tag <= 255 ) {
271
+ ensureCapacity (1 +1 );
272
+ addUnchecked ((byte ) 0xee );
273
+ append (tag , 1 );
274
+ } else {
275
+ ensureCapacity (1 +8 );
276
+ addUnchecked ((byte ) 0xef );
277
+ append (tag , LONG_BYTES );
278
+ }
279
+ }
280
+
274
281
public VPackBuilder add (final ValueType value ) throws VPackBuilderException {
275
282
return addInternal (VALUE_TYPE , value );
276
283
}
@@ -430,12 +437,180 @@ public VPackBuilder add(final String attribute, final VPackSlice value) throws V
430
437
return addInternal (attribute , VPACK , value );
431
438
}
432
439
440
+ public VPackBuilder addTagged (final long tag , final ValueType value ) throws VPackBuilderException {
441
+ return addInternal (tag , VALUE_TYPE , value );
442
+ }
443
+
444
+ public VPackBuilder addTagged (final long tag , final ValueType value , final boolean unindexed ) throws VPackBuilderException {
445
+ return addInternal (tag , VALUE , new Value (value , unindexed ));
446
+ }
447
+
448
+ public VPackBuilder addTagged (final long tag , final Boolean value ) throws VPackBuilderException {
449
+ return addInternal (tag , BOOLEAN , value );
450
+ }
451
+
452
+ public VPackBuilder addTagged (final long tag , final Double value ) throws VPackBuilderException {
453
+ return addInternal (tag , DOUBLE , value );
454
+ }
455
+
456
+ public VPackBuilder addTagged (final long tag , final Float value ) throws VPackBuilderException {
457
+ return addInternal (tag , FLOAT , value );
458
+ }
459
+
460
+ public VPackBuilder addTagged (final long tag , final BigDecimal value ) throws VPackBuilderException {
461
+ return addInternal (tag , BIG_DECIMAL , value );
462
+ }
463
+
464
+ public VPackBuilder addTagged (final long tag , final Long value ) throws VPackBuilderException {
465
+ return addInternal (tag , LONG , value );
466
+ }
467
+
468
+ public VPackBuilder addTagged (final long tag , final Long value , final ValueType type ) throws VPackBuilderException {
469
+ return addInternal (tag , VALUE , new Value (value , type ));
470
+ }
471
+
472
+ public VPackBuilder addTagged (final long tag , final Integer value ) throws VPackBuilderException {
473
+ return addInternal (tag , INTEGER , value );
474
+ }
475
+
476
+ public VPackBuilder addTagged (final long tag , final Short value ) throws VPackBuilderException {
477
+ return addInternal (tag , SHORT , value );
478
+ }
479
+
480
+ public VPackBuilder addTagged (final long tag , final BigInteger value ) throws VPackBuilderException {
481
+ return addInternal (tag , BIG_INTEGER , value );
482
+ }
483
+
484
+ public VPackBuilder addTagged (final long tag , final BigInteger value , final ValueType type ) throws VPackBuilderException {
485
+ return addInternal (tag , VALUE , new Value (value , type ));
486
+ }
487
+
488
+ public VPackBuilder addTagged (final long tag , final Date value ) throws VPackBuilderException {
489
+ return addInternal (tag , DATE , value );
490
+ }
491
+
492
+ public VPackBuilder addTagged (final long tag , final java .sql .Date value ) throws VPackBuilderException {
493
+ return addInternal (tag , SQL_DATE , value );
494
+ }
495
+
496
+ public VPackBuilder addTagged (final long tag , final java .sql .Timestamp value ) throws VPackBuilderException {
497
+ return addInternal (tag , SQL_TIMESTAMP , value );
498
+ }
499
+
500
+ public VPackBuilder addTagged (final long tag , final String value ) throws VPackBuilderException {
501
+ return addInternal (tag , STRING , value );
502
+ }
503
+
504
+ public VPackBuilder addTagged (final long tag , final Character value ) throws VPackBuilderException {
505
+ return addInternal (tag , CHARACTER , value );
506
+ }
507
+
508
+ public VPackBuilder addTagged (final long tag , final byte [] value ) throws VPackBuilderException {
509
+ return addInternal (tag , BYTE_ARRAY , value );
510
+ }
511
+
512
+ public VPackBuilder addTagged (final long tag , final VPackSlice value ) throws VPackBuilderException {
513
+ return addInternal (tag , VPACK , value );
514
+ }
515
+
516
+ public VPackBuilder addTagged (final String attribute , final long tag , final ValueType value ) throws VPackBuilderException {
517
+ return addInternal (attribute , tag , VALUE_TYPE , value );
518
+ }
519
+
520
+ public VPackBuilder addTagged (final String attribute , final long tag , final ValueType value , final boolean unindexed )
521
+ throws VPackBuilderException {
522
+ return addInternal (attribute , tag , VALUE , new Value (value , unindexed ));
523
+ }
524
+
525
+ public VPackBuilder addTagged (final String attribute , final long tag , final Boolean value ) throws VPackBuilderException {
526
+ return addInternal (attribute , tag , BOOLEAN , value );
527
+ }
528
+
529
+ public VPackBuilder addTagged (final String attribute , final long tag , final Double value ) throws VPackBuilderException {
530
+ return addInternal (attribute , tag , DOUBLE , value );
531
+ }
532
+
533
+ public VPackBuilder addTagged (final String attribute , final long tag , final Float value ) throws VPackBuilderException {
534
+ return addInternal (attribute , tag , FLOAT , value );
535
+ }
536
+
537
+ public VPackBuilder addTagged (final String attribute , final long tag , final BigDecimal value ) throws VPackBuilderException {
538
+ return addInternal (attribute , tag , BIG_DECIMAL , value );
539
+ }
540
+
541
+ public VPackBuilder addTagged (final String attribute , final long tag , final Long value ) throws VPackBuilderException {
542
+ return addInternal (attribute , tag , LONG , value );
543
+ }
544
+
545
+ public VPackBuilder addTagged (final String attribute , final long tag , final Long value , final ValueType type )
546
+ throws VPackBuilderException {
547
+ return addInternal (attribute , tag , VALUE , new Value (value , type ));
548
+ }
549
+
550
+ public VPackBuilder addTagged (final String attribute , final long tag , final Integer value ) throws VPackBuilderException {
551
+ return addInternal (attribute , tag , INTEGER , value );
552
+ }
553
+
554
+ public VPackBuilder addTagged (final String attribute , final long tag , final Short value ) throws VPackBuilderException {
555
+ return addInternal (attribute , tag , SHORT , value );
556
+ }
557
+
558
+ public VPackBuilder addTagged (final String attribute , final long tag , final Byte value ) throws VPackBuilderException {
559
+ return addInternal (attribute , tag , BYTE , value );
560
+ }
561
+
562
+ public VPackBuilder addTagged (final String attribute , final long tag , final BigInteger value ) throws VPackBuilderException {
563
+ return addInternal (attribute , tag , BIG_INTEGER , value );
564
+ }
565
+
566
+ public VPackBuilder addTagged (final String attribute , final long tag , final BigInteger value , final ValueType type )
567
+ throws VPackBuilderException {
568
+ return addInternal (attribute , tag , VALUE , new Value (value , type ));
569
+ }
570
+
571
+ public VPackBuilder addTagged (final String attribute , final long tag , final String value ) throws VPackBuilderException {
572
+ return addInternal (attribute , tag , STRING , value );
573
+ }
574
+
575
+ public VPackBuilder addTagged (final String attribute , final long tag , final Character value ) throws VPackBuilderException {
576
+ return addInternal (attribute , tag , CHARACTER , value );
577
+ }
578
+
579
+ public VPackBuilder addTagged (final String attribute , final long tag , final Date value ) throws VPackBuilderException {
580
+ return addInternal (attribute , tag , DATE , value );
581
+ }
582
+
583
+ public VPackBuilder addTagged (final String attribute , final long tag , final java .sql .Date value ) throws VPackBuilderException {
584
+ return addInternal (attribute , tag , SQL_DATE , value );
585
+ }
586
+
587
+ public VPackBuilder addTagged (final String attribute , final long tag , final java .sql .Timestamp value ) throws VPackBuilderException {
588
+ return addInternal (attribute , tag , SQL_TIMESTAMP , value );
589
+ }
590
+
591
+ public VPackBuilder addTagged (final String attribute , final long tag , final byte [] value ) throws VPackBuilderException {
592
+ return addInternal (attribute , tag , BYTE_ARRAY , value );
593
+ }
594
+
595
+ public VPackBuilder addTagged (final String attribute , final long tag , final VPackSlice value ) throws VPackBuilderException {
596
+ return addInternal (attribute , tag , VPACK , value );
597
+ }
598
+
433
599
private <T > VPackBuilder addInternal (final Appender <T > appender , final T value ) throws VPackBuilderException {
600
+ return addInternal (0 , appender , value );
601
+ }
602
+
603
+ private <T > VPackBuilder addInternal (final long tag , final Appender <T > appender , final T value ) throws VPackBuilderException {
434
604
boolean haveReported = false ;
435
605
if (!stack .isEmpty () && !keyWritten ) {
436
606
reportAdd ();
437
607
haveReported = true ;
438
608
}
609
+
610
+ if (tag != 0 ) {
611
+ appendTag (tag );
612
+ }
613
+
439
614
try {
440
615
if (value == null ) {
441
616
appendNull ();
@@ -454,6 +629,11 @@ private <T> VPackBuilder addInternal(final Appender<T> appender, final T value)
454
629
455
630
private <T > VPackBuilder addInternal (final String attribute , final Appender <T > appender , final T value )
456
631
throws VPackBuilderException {
632
+ return addInternal (attribute , 0 , appender , value );
633
+ }
634
+
635
+ private <T > VPackBuilder addInternal (final String attribute , final long tag , final Appender <T > appender , final T value )
636
+ throws VPackBuilderException {
457
637
if (attribute != null ) {
458
638
boolean haveReported = false ;
459
639
if (!stack .isEmpty ()) {
@@ -488,6 +668,11 @@ private <T> VPackBuilder addInternal(final String attribute, final Appender<T> a
488
668
}
489
669
STRING .append (this , attribute );
490
670
keyWritten = true ;
671
+
672
+ if (tag != 0 ) {
673
+ appendTag (tag );
674
+ }
675
+
491
676
if (value == null ) {
492
677
appendNull ();
493
678
} else {
0 commit comments