Skip to content

Add tags support #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
/.idea
/*.iml
*.jfr
/.gradle
/bin
/build
209 changes: 201 additions & 8 deletions src/main/java/com/arangodb/velocypack/VPackBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@ private void ensureCapacity(final int minCapacity) {
}
}

private void appendTag(long tag) {
if(tag <= 255) {
ensureCapacity(1+1);
addUnchecked((byte) 0xee);
append(tag, 1);
} else {
ensureCapacity(1+8);
addUnchecked((byte) 0xef);
append(tag, LONG_BYTES);
}
}

public VPackBuilder add(final ValueType value) throws VPackBuilderException {
return addInternal(VALUE_TYPE, value);
}
Expand Down Expand Up @@ -425,12 +437,180 @@ public VPackBuilder add(final String attribute, final VPackSlice value) throws V
return addInternal(attribute, VPACK, value);
}

public VPackBuilder addTagged(final long tag, final ValueType value) throws VPackBuilderException {
return addInternal(tag, VALUE_TYPE, value);
}

public VPackBuilder addTagged(final long tag, final ValueType value, final boolean unindexed) throws VPackBuilderException {
return addInternal(tag, VALUE, new Value(value, unindexed));
}

public VPackBuilder addTagged(final long tag, final Boolean value) throws VPackBuilderException {
return addInternal(tag, BOOLEAN, value);
}

public VPackBuilder addTagged(final long tag, final Double value) throws VPackBuilderException {
return addInternal(tag, DOUBLE, value);
}

public VPackBuilder addTagged(final long tag, final Float value) throws VPackBuilderException {
return addInternal(tag, FLOAT, value);
}

public VPackBuilder addTagged(final long tag, final BigDecimal value) throws VPackBuilderException {
return addInternal(tag, BIG_DECIMAL, value);
}

public VPackBuilder addTagged(final long tag, final Long value) throws VPackBuilderException {
return addInternal(tag, LONG, value);
}

public VPackBuilder addTagged(final long tag, final Long value, final ValueType type) throws VPackBuilderException {
return addInternal(tag, VALUE, new Value(value, type));
}

public VPackBuilder addTagged(final long tag, final Integer value) throws VPackBuilderException {
return addInternal(tag, INTEGER, value);
}

public VPackBuilder addTagged(final long tag, final Short value) throws VPackBuilderException {
return addInternal(tag, SHORT, value);
}

public VPackBuilder addTagged(final long tag, final BigInteger value) throws VPackBuilderException {
return addInternal(tag, BIG_INTEGER, value);
}

public VPackBuilder addTagged(final long tag, final BigInteger value, final ValueType type) throws VPackBuilderException {
return addInternal(tag, VALUE, new Value(value, type));
}

public VPackBuilder addTagged(final long tag, final Date value) throws VPackBuilderException {
return addInternal(tag, DATE, value);
}

public VPackBuilder addTagged(final long tag, final java.sql.Date value) throws VPackBuilderException {
return addInternal(tag, SQL_DATE, value);
}

public VPackBuilder addTagged(final long tag, final java.sql.Timestamp value) throws VPackBuilderException {
return addInternal(tag, SQL_TIMESTAMP, value);
}

public VPackBuilder addTagged(final long tag, final String value) throws VPackBuilderException {
return addInternal(tag, STRING, value);
}

public VPackBuilder addTagged(final long tag, final Character value) throws VPackBuilderException {
return addInternal(tag, CHARACTER, value);
}

public VPackBuilder addTagged(final long tag, final byte[] value) throws VPackBuilderException {
return addInternal(tag, BYTE_ARRAY, value);
}

public VPackBuilder addTagged(final long tag, final VPackSlice value) throws VPackBuilderException {
return addInternal(tag, VPACK, value);
}

public VPackBuilder addTagged(final String attribute, final long tag, final ValueType value) throws VPackBuilderException {
return addInternal(attribute, tag, VALUE_TYPE, value);
}

public VPackBuilder addTagged(final String attribute, final long tag, final ValueType value, final boolean unindexed)
throws VPackBuilderException {
return addInternal(attribute, tag, VALUE, new Value(value, unindexed));
}

public VPackBuilder addTagged(final String attribute, final long tag, final Boolean value) throws VPackBuilderException {
return addInternal(attribute, tag, BOOLEAN, value);
}

public VPackBuilder addTagged(final String attribute, final long tag, final Double value) throws VPackBuilderException {
return addInternal(attribute, tag, DOUBLE, value);
}

public VPackBuilder addTagged(final String attribute, final long tag, final Float value) throws VPackBuilderException {
return addInternal(attribute, tag, FLOAT, value);
}

public VPackBuilder addTagged(final String attribute, final long tag, final BigDecimal value) throws VPackBuilderException {
return addInternal(attribute, tag, BIG_DECIMAL, value);
}

public VPackBuilder addTagged(final String attribute, final long tag, final Long value) throws VPackBuilderException {
return addInternal(attribute, tag, LONG, value);
}

public VPackBuilder addTagged(final String attribute, final long tag, final Long value, final ValueType type)
throws VPackBuilderException {
return addInternal(attribute, tag, VALUE, new Value(value, type));
}

public VPackBuilder addTagged(final String attribute, final long tag, final Integer value) throws VPackBuilderException {
return addInternal(attribute, tag, INTEGER, value);
}

public VPackBuilder addTagged(final String attribute, final long tag, final Short value) throws VPackBuilderException {
return addInternal(attribute, tag, SHORT, value);
}

public VPackBuilder addTagged(final String attribute, final long tag, final Byte value) throws VPackBuilderException {
return addInternal(attribute, tag, BYTE, value);
}

public VPackBuilder addTagged(final String attribute, final long tag, final BigInteger value) throws VPackBuilderException {
return addInternal(attribute, tag, BIG_INTEGER, value);
}

public VPackBuilder addTagged(final String attribute, final long tag, final BigInteger value, final ValueType type)
throws VPackBuilderException {
return addInternal(attribute, tag, VALUE, new Value(value, type));
}

public VPackBuilder addTagged(final String attribute, final long tag, final String value) throws VPackBuilderException {
return addInternal(attribute, tag, STRING, value);
}

public VPackBuilder addTagged(final String attribute, final long tag, final Character value) throws VPackBuilderException {
return addInternal(attribute, tag, CHARACTER, value);
}

public VPackBuilder addTagged(final String attribute, final long tag, final Date value) throws VPackBuilderException {
return addInternal(attribute, tag, DATE, value);
}

public VPackBuilder addTagged(final String attribute, final long tag, final java.sql.Date value) throws VPackBuilderException {
return addInternal(attribute, tag, SQL_DATE, value);
}

public VPackBuilder addTagged(final String attribute, final long tag, final java.sql.Timestamp value) throws VPackBuilderException {
return addInternal(attribute, tag, SQL_TIMESTAMP, value);
}

public VPackBuilder addTagged(final String attribute, final long tag, final byte[] value) throws VPackBuilderException {
return addInternal(attribute, tag, BYTE_ARRAY, value);
}

public VPackBuilder addTagged(final String attribute, final long tag, final VPackSlice value) throws VPackBuilderException {
return addInternal(attribute, tag, VPACK, value);
}

private <T> VPackBuilder addInternal(final Appender<T> appender, final T value) throws VPackBuilderException {
return addInternal(0, appender, value);
}

private <T> VPackBuilder addInternal(final long tag, final Appender<T> appender, final T value) throws VPackBuilderException {
boolean haveReported = false;
if (!stack.isEmpty() && !keyWritten) {
reportAdd();
haveReported = true;
}

if (tag != 0) {
appendTag(tag);
}

try {
if (value == null) {
appendNull();
Expand All @@ -449,6 +629,11 @@ private <T> VPackBuilder addInternal(final Appender<T> appender, final T value)

private <T> VPackBuilder addInternal(final String attribute, final Appender<T> appender, final T value)
throws VPackBuilderException {
return addInternal(attribute, 0, appender, value);
}

private <T> VPackBuilder addInternal(final String attribute, final long tag, final Appender<T> appender, final T value)
throws VPackBuilderException {
if (attribute != null) {
boolean haveReported = false;
if (!stack.isEmpty()) {
Expand All @@ -466,10 +651,12 @@ private <T> VPackBuilder addInternal(final String attribute, final Appender<T> a
if (VPackSlice.attributeTranslator != null) {
final VPackSlice translate = VPackSlice.attributeTranslator.translate(attribute);
if (translate != null) {
final byte[] trValue = translate.getRawVPack();
ensureCapacity(size + trValue.length);
for (byte b : trValue) {
addUnchecked(b);
final byte[] trValue = translate.getBuffer();
int trValueLength = translate.getByteSize();
int trValueStart = translate.getStart();
ensureCapacity(size + trValueLength);
for (int i = 0; i < trValueLength; i++) {
addUnchecked(trValue[i+trValueStart]);
}
keyWritten = true;
if (value == null) {
Expand All @@ -483,6 +670,11 @@ private <T> VPackBuilder addInternal(final String attribute, final Appender<T> a
}
STRING.append(this, attribute);
keyWritten = true;

if (tag != 0) {
appendTag(tag);
}

if (value == null) {
appendNull();
} else {
Expand Down Expand Up @@ -646,10 +838,11 @@ private void appendBinary(final byte[] value) {
}

private void appendVPack(final VPackSlice value) {
final byte[] vpack = value.getRawVPack();
ensureCapacity(size + vpack.length);
System.arraycopy(vpack, 0, buffer, size, vpack.length);
size += vpack.length;
final byte[] vpack = value.getBuffer();
int length = value.getByteSize();
ensureCapacity(size + length);
System.arraycopy(vpack, value.getStart(), buffer, size, length);
size += length;
}

private void addArray(final boolean unindexed) {
Expand Down
Loading