use of com.linkedin.data.codec.ProtobufDataCodec in project rest.li by linkedin.
the class TestProtobufDataDecoder method testDecoder.
@Test(dataProvider = "protobufCodecData", dataProviderClass = CodecDataProviders.class)
public void testDecoder(String testName, DataComplex dataComplex, boolean enableFixedLengthFloatDoubles) throws Exception {
ProtobufDataCodec codec = new ProtobufDataCodec(new ProtobufCodecOptions.Builder().setEnableFixedLengthFloatDoubles(enableFixedLengthFloatDoubles).setEnableASCIIOnlyStrings(true).build());
byte[] bytes = TestUtil.dataComplexToBytes(codec, dataComplex);
DataComplex decodedDataComplex = decode(bytes, 20);
assertEquals(TestUtil.dataComplexToBytes(codec, decodedDataComplex), bytes);
}
use of com.linkedin.data.codec.ProtobufDataCodec in project rest.li by linkedin.
the class TestProtobufDataDecoder method testLongValues.
@Test
public void testLongValues() throws Exception {
long longInc = (Long.MAX_VALUE - Long.MAX_VALUE / 100L) / 10000L;
for (long i = Long.MAX_VALUE / 100L; i <= Long.MAX_VALUE && i > 0; i += longInc) {
DataMap dataMap = new DataMap();
dataMap.put("long", i);
byte[] bytes = TestUtil.dataComplexToBytes(new ProtobufDataCodec(new ProtobufCodecOptions.Builder().build()), dataMap);
DataMap decodedMap = (DataMap) decode(bytes, 20);
assertEquals(decodedMap.getLong("long"), Long.valueOf(i));
}
for (long i = Long.MIN_VALUE; i <= Long.MIN_VALUE / 100L && i < 0; i += longInc) {
DataMap dataMap = new DataMap();
dataMap.put("long", i);
byte[] bytes = TestUtil.dataComplexToBytes(new ProtobufDataCodec(new ProtobufCodecOptions.Builder().build()), dataMap);
DataMap decodedMap = (DataMap) decode(bytes, 20);
assertEquals(decodedMap.getLong("long"), Long.valueOf(i));
}
}
use of com.linkedin.data.codec.ProtobufDataCodec in project rest.li by linkedin.
the class TestProtobufDataDecoder method testInvalidList.
@Test
public void testInvalidList() throws Exception {
DataMap dataMap = new DataMap();
dataMap.put("key", true);
byte[] bytes = TestUtil.dataComplexToBytes(new ProtobufDataCodec(new ProtobufCodecOptions.Builder().build()), dataMap);
decode(bytes, 3);
try {
decodeList(bytes);
fail("Parsing map as list");
} catch (ExecutionException e) {
// Expected.
}
}
Aggregations