Skip to content

Commit 2e7537c

Browse files
committed
add tags support, minor performance upgrades
1 parent 5e91dce commit 2e7537c

File tree

6 files changed

+380
-34
lines changed

6 files changed

+380
-34
lines changed

src/main/java/com/arangodb/velocypack/VPackBuilder.java

Lines changed: 190 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,16 @@
2020

2121
package com.arangodb.velocypack;
2222

23-
import java.io.UnsupportedEncodingException;
2423
import java.math.BigDecimal;
2524
import java.math.BigInteger;
2625
import java.nio.charset.StandardCharsets;
2726
import java.sql.Timestamp;
2827
import java.util.ArrayList;
2928
import java.util.Arrays;
3029
import java.util.Collection;
31-
import java.util.Collections;
3230
import java.util.Comparator;
3331
import java.util.Date;
34-
import java.util.HashMap;
3532
import java.util.List;
36-
import java.util.Map;
3733

3834
import com.arangodb.velocypack.exception.VPackBuilderException;
3935
import com.arangodb.velocypack.exception.VPackBuilderKeyAlreadyWrittenException;
@@ -47,7 +43,6 @@
4743
import com.arangodb.velocypack.internal.DefaultVPackBuilderOptions;
4844
import com.arangodb.velocypack.internal.Value;
4945
import com.arangodb.velocypack.internal.util.NumberUtil;
50-
import com.fasterxml.jackson.core.io.CharTypes;
5146

5247
/**
5348
* @author Mark Vollmary
@@ -271,6 +266,18 @@ private void ensureCapacity(final int minCapacity) {
271266
}
272267
}
273268

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+
274281
public VPackBuilder add(final ValueType value) throws VPackBuilderException {
275282
return addInternal(VALUE_TYPE, value);
276283
}
@@ -430,12 +437,180 @@ public VPackBuilder add(final String attribute, final VPackSlice value) throws V
430437
return addInternal(attribute, VPACK, value);
431438
}
432439

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+
433599
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 {
434604
boolean haveReported = false;
435605
if (!stack.isEmpty() && !keyWritten) {
436606
reportAdd();
437607
haveReported = true;
438608
}
609+
610+
if (tag != 0) {
611+
appendTag(tag);
612+
}
613+
439614
try {
440615
if (value == null) {
441616
appendNull();
@@ -454,6 +629,11 @@ private <T> VPackBuilder addInternal(final Appender<T> appender, final T value)
454629

455630
private <T> VPackBuilder addInternal(final String attribute, final Appender<T> appender, final T value)
456631
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 {
457637
if (attribute != null) {
458638
boolean haveReported = false;
459639
if (!stack.isEmpty()) {
@@ -488,6 +668,11 @@ private <T> VPackBuilder addInternal(final String attribute, final Appender<T> a
488668
}
489669
STRING.append(this, attribute);
490670
keyWritten = true;
671+
672+
if (tag != 0) {
673+
appendTag(tag);
674+
}
675+
491676
if (value == null) {
492677
appendNull();
493678
} else {

0 commit comments

Comments
 (0)