Skip to content

Error while serializing long values with VPackBuilder #73

Closed
@christian-lechner

Description

@christian-lechner

Hello!

I think I've found a bug while serializing long values with VPackBuilder:

private static final Appender<Long> LONG = new Appender<Long>() {
	@Override
	public void append(final VPackBuilder builder, final Long value) throws VPackBuilderException {
		if (value <= 9 && value >= -6) {
			builder.appendSmallInt(value);
		} else {
			builder.add((byte) 0x23);
			builder.append(value, INTEGER_BYTES);
		}
	}
};

Shouldn't the line builder.append(value, INTEGER_BYTES); read builder.append(value, LONG_BYTES);?

The same for BIG_INTEGER?

private static final Appender<BigInteger> BIG_INTEGER = new Appender<BigInteger>() {
	@Override
	public void append(final VPackBuilder builder, final BigInteger value) throws VPackBuilderException {
		if (value.longValue() <= 9 && value.longValue() >= -6) {
			builder.appendSmallInt(value.longValue());
		} else {
			builder.add((byte) 0x23);
			builder.append(value, INTEGER_BYTES);
		}
	}
};

Test code:

long value = 12345678901L;
VPackBuilder builder = new VPackBuilder();
builder.add(value);
VPackSlice vpack = builder.slice();
System.out.println(vpack);   // output: 3755744309

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions