use of org.apache.thrift.TSerializer in project tsfile by thulab.
the class ReadWriteThriftFormatUtils method write.
/**
* @param tbase
* input class in thrift format
* @param to
* OutputStream
* @throws IOException
* exception in IO
*/
public static void write(TBase<?, ?> tbase, OutputStream to) throws IOException {
try {
TSerializer serializer = new TSerializer(new TCompactProtocol.Factory());
to.write(serializer.serialize(tbase));
} catch (TException e) {
LOGGER.error("tsfile-file Utils: can not write {}", tbase, e);
throw new IOException(e);
}
}
use of org.apache.thrift.TSerializer in project SpinalTap by airbnb.
the class ColumnSerializationUtilTest method testDeserializeColumn.
@Test
public void testDeserializeColumn() throws Exception {
Mutation mutation = new Mutation(MutationType.DELETE, TIMESTAMP, SOURCE_ID, DATA_SOURCE, BINLOG_HEADER, TABLE, getEntity());
TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());
TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
byte[] serialized = serializer.serialize(mutation);
Mutation deserialized = new Mutation();
deserializer.deserialize(deserialized, serialized);
assertEquals(mutation, deserialized);
}
use of org.apache.thrift.TSerializer in project beam by apache.
the class BeamKafkaTableThriftTest method generateEncodedPayload.
@Override
protected byte[] generateEncodedPayload(int i) {
final TestThriftMessage message = new TestThriftMessage().setFLong(i).setFInt(i).setFDouble(i).setFString("thrift_value" + i);
message.addToFDoubleArray(i);
try {
return new TSerializer(protocolFactory).serialize(message);
} catch (TException e) {
throw new RuntimeException(e);
}
}
use of org.apache.thrift.TSerializer in project beam by apache.
the class ThriftPayloadSerializerProviderTest method deserialize.
@Test
public void deserialize() throws Exception {
Row row = provider.getSerializer(SHUFFLED_SCHEMA, ImmutableMap.of("thriftClass", TestThriftMessage.class.getName(), "thriftProtocolFactoryClass", TCompactProtocol.Factory.class.getName())).deserialize(new TSerializer(new TCompactProtocol.Factory()).serialize(MESSAGE));
assertEquals(ROW, row);
}
use of org.apache.thrift.TSerializer in project druid by druid-io.
the class ThriftInputRowParserTest method testParse.
@Test
public void testParse() throws Exception {
ThriftInputRowParser parser = new ThriftInputRowParser(parseSpec, "example/book.jar", "org.apache.druid.data.input.thrift.Book");
Book book = new Book().setDate("2016-08-29").setPrice(19.9).setTitle("title").setAuthor(new Author().setFirstName("first").setLastName("last"));
TSerializer serializer;
byte[] bytes;
// 1. compact
serializer = new TSerializer(new TCompactProtocol.Factory());
bytes = serializer.serialize(book);
serializationAndTest(parser, bytes);
// 2. binary + base64
serializer = new TSerializer(new TBinaryProtocol.Factory());
serializationAndTest(parser, StringUtils.encodeBase64(serializer.serialize(book)));
// 3. json
serializer = new TSerializer(new TJSONProtocol.Factory());
bytes = serializer.serialize(book);
serializationAndTest(parser, bytes);
}
Aggregations