@Test public void stress_read_large() throws Exception { int count = 10000000; DecimalOption value = new DecimalOption(new BigDecimal(Long.MAX_VALUE).multiply(BigDecimal.TEN)); byte[] bytes = toBytes(value); DecimalOption buf = new DecimalOption(); DataInputBuffer in = new DataInputBuffer(); for (int i = 0; i < count; i++) { in.reset(bytes, bytes.length); buf.readFields(in); if (i == 0) { assertThat(buf, is(value)); } } }
@SuppressWarnings("deprecation") @Override public void readFields(DataInput in) throws IOException { int head = in.readByte() & 0xff; if ((head & MASK_PRESENT) == 0) { setNull(); return; } boolean plus = (head & MASK_PLUS) != 0; int scale = WritableUtils.readVInt(in); int length = WritableUtils.readVInt(in); DecimalBuffer buffer = BUFFER_MAIN.get(); byte[] target = buffer.setMeta(plus, scale, length); in.readFully(target, target.length - length, length); modify(buffer.toBigDecimal()); }
DecimalOption extends ValueOption<DecimalOption> { @SuppressWarnings("deprecation") @Override public void readFields(DataInput in) throws IOException { int head = in.readByte() & 0xff; if ((head & MASK_PRESENT) == 0) { setNull(); return; } boolean plus = (head & MASK_PLUS) != 0; int scale = WritableUtils.readVInt(in); int length = WritableUtils.readVInt(in); DecimalBuffer buffer = BUFFER_MAIN.get(); byte[] target = buffer.setMeta(plus, scale, length); in.readFully(target, target.length - length, length); modify(buffer.toBigDecimal()); } }
DecimalOption extends ValueOption<DecimalOption> { @SuppressWarnings("deprecation") @Override public void readFields(DataInput in) throws IOException { int head = in.readByte() & 0xff; if ((head & MASK_PRESENT) == 0) { setNull(); return; } boolean plus = (head & MASK_PLUS) != 0; int scale = WritableUtils.readVInt(in); int length = WritableUtils.readVInt(in); DecimalBuffer buffer = BUFFER_MAIN.get(); byte[] target = buffer.setMeta(plus, scale, length); in.readFully(target, target.length - length, length); modify(buffer.toBigDecimal()); } DecimalOption();  DecimalOption(BigDecimal valueOrNull); }
DecimalOption extends ValueOption<DecimalOption> { @SuppressWarnings("deprecation") @Override public void readFields(DataInput in) throws IOException { int head = in.readByte() & 0xff; if ((head & MASK_PRESENT) == 0) { setNull(); return; } boolean plus = (head & MASK_PLUS) != 0; int scale = WritableUtils.readVInt(in); int length = WritableUtils.readVInt(in); DecimalBuffer buffer = BUFFER_MAIN.get(); byte[] target = buffer.setMeta(plus, scale, length); in.readFully(target, target.length - length, length); modify(buffer.toBigDecimal()); } DecimalOption();  DecimalOption(BigDecimal valueOrNull); BigDecimal get(); BigDecimal or(BigDecimal alternate); void add(BigDecimal delta); void add(DecimalOption other); @Deprecated DecimalOption modify(BigDecimal newValue); @Override @Deprecated void copyFrom(DecimalOption optionOrNull); @Override int hashCode(); @Override boolean equals(Object obj); boolean has(BigDecimal other); @Override int compareTo(WritableRawComparable o); @Override String toString(); @Override void write(DataOutput out); @SuppressWarnings("deprecation") @Override void readFields(DataInput in); @SuppressWarnings("deprecation") @Override int restore(byte[] bytes, int offset, int limit); @Override int getSizeInBytes(byte[] buf, int offset); @Override int compareInBytes(byte[] b1, int o1, byte[] b2, int o2); static int getBytesLength(byte[] bytes, int offset, int length); static int compareBytes(
            byte[] b1, int s1, int l1,
            byte[] b2, int s2, int l2); }
DecimalOption extends ValueOption<DecimalOption> { @SuppressWarnings("deprecation") @Override public void readFields(DataInput in) throws IOException { int head = in.readByte() & 0xff; if ((head & MASK_PRESENT) == 0) { setNull(); return; } boolean plus = (head & MASK_PLUS) != 0; int scale = WritableUtils.readVInt(in); int length = WritableUtils.readVInt(in); DecimalBuffer buffer = BUFFER_MAIN.get(); byte[] target = buffer.setMeta(plus, scale, length); in.readFully(target, target.length - length, length); modify(buffer.toBigDecimal()); } DecimalOption();  DecimalOption(BigDecimal valueOrNull); BigDecimal get(); BigDecimal or(BigDecimal alternate); void add(BigDecimal delta); void add(DecimalOption other); @Deprecated DecimalOption modify(BigDecimal newValue); @Override @Deprecated void copyFrom(DecimalOption optionOrNull); @Override int hashCode(); @Override boolean equals(Object obj); boolean has(BigDecimal other); @Override int compareTo(WritableRawComparable o); @Override String toString(); @Override void write(DataOutput out); @SuppressWarnings("deprecation") @Override void readFields(DataInput in); @SuppressWarnings("deprecation") @Override int restore(byte[] bytes, int offset, int limit); @Override int getSizeInBytes(byte[] buf, int offset); @Override int compareInBytes(byte[] b1, int o1, byte[] b2, int o2); static int getBytesLength(byte[] bytes, int offset, int length); static int compareBytes(
            byte[] b1, int s1, int l1,
            byte[] b2, int s2, int l2);  }