use of org.apache.hadoop.hbase.util.PositionedByteRange in project hbase by apache.
the class TestUnion2 method testEncodeDecode.
@Test
public void testEncodeDecode() {
Integer intVal = Integer.valueOf(10);
String strVal = "hello";
PositionedByteRange buff = new SimplePositionedMutableByteRange(10);
SampleUnion1 type = new SampleUnion1();
type.encode(buff, intVal);
buff.setPosition(0);
assertTrue(0 == intVal.compareTo(type.decodeA(buff)));
buff.setPosition(0);
type.encode(buff, strVal);
buff.setPosition(0);
assertTrue(0 == strVal.compareTo(type.decodeB(buff)));
}
use of org.apache.hadoop.hbase.util.PositionedByteRange in project hbase by apache.
the class FixedLengthWrapper method decode.
@Override
public T decode(PositionedByteRange src) {
if (src.getRemaining() < length) {
throw new IllegalArgumentException("Not enough buffer remaining. src.offset: " + src.getOffset() + " src.length: " + src.getLength() + " src.position: " + src.getPosition() + " max length: " + length);
}
// create a copy range limited to length bytes. boo.
PositionedByteRange b = new SimplePositionedMutableByteRange(length);
src.get(b.getBytes());
return base.decode(b);
}
use of org.apache.hadoop.hbase.util.PositionedByteRange in project hbase by apache.
the class TestFixedLengthWrapper method testInsufficientRemainingWrite.
@Test(expected = IllegalArgumentException.class)
public void testInsufficientRemainingWrite() {
PositionedByteRange buff = new SimplePositionedMutableByteRange(0);
DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(), 3);
type.encode(buff, Bytes.toBytes(""));
}
use of org.apache.hadoop.hbase.util.PositionedByteRange in project hbase by apache.
the class TestFixedLengthWrapper method testReadWrite.
@Test
public void testReadWrite() {
for (int limit : limits) {
PositionedByteRange buff = new SimplePositionedMutableByteRange(limit);
for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
for (byte[] val : VALUES) {
buff.setPosition(0);
DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(ord), limit);
assertEquals(limit, type.encode(buff, val));
buff.setPosition(0);
byte[] actual = type.decode(buff);
assertTrue("Decoding output differs from expected", Bytes.equals(val, 0, val.length, actual, 0, val.length));
buff.setPosition(0);
assertEquals(limit, type.skip(buff));
}
}
}
}
use of org.apache.hadoop.hbase.util.PositionedByteRange in project hbase by apache.
the class TestFixedLengthWrapper method testInsufficientRemainingRead.
@Test(expected = IllegalArgumentException.class)
public void testInsufficientRemainingRead() {
PositionedByteRange buff = new SimplePositionedMutableByteRange(0);
DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(), 3);
type.decode(buff);
}
Aggregations