Protocol buffers 将protobuf转换为avro
我将数据序列化为protobuff格式,并希望将其转换为Avro序列化 我可以使用Protocol buffers 将protobuf转换为avro,protocol-buffers,avro,Protocol Buffers,Avro,我将数据序列化为protobuff格式,并希望将其转换为Avro序列化 我可以使用 ProtoTest.Msg msg = buildMessage(); ProtobufData protobufData = ProtobufData.get(); Schema protoSchema = protobufData.getSchema(ProtoTest.Msg.class); Object o = protobufData.newRecord(msg, pro
ProtoTest.Msg msg = buildMessage();
ProtobufData protobufData = ProtobufData.get();
Schema protoSchema = protobufData.getSchema(ProtoTest.Msg.class);
Object o = protobufData.newRecord(msg, protoSchema);
生成的o再次是protobuf对象。现在我想用相同的模式将o写成avro
GenericDatumWriter genericDatumWriter = new GenericDatumWriter(protoSchema);
OutputStream out = new ByteArrayOutputStream();
Encoder encoder = EncoderFactory.get().binaryEncoder(out, null );
genericDatumWriter.write(o, encoder);
但是运行上面的代码会在write方法中引发下一个异常
如何将原始对象转换为avro对象
问候,,
Ronen.您应该使用ProtobufDatumWriter而不是GenericDatumWriter 另外,使用ProtobufDatumReader读取protobuf数据 最后,Avro的邮件列表会更及时地回答Avro的问题
嗨,罗南,你找到克服这个问题的方法了吗?我也有同样的经历。
java.lang.ClassCastException: example.avro.ProtoTest$Msg cannot be cast to org.apache.avro.generic.IndexedRecord
at org.apache.avro.generic.GenericData.getField(GenericData.java:526)
at org.apache.avro.generic.GenericData.getField(GenericData.java:541)
at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:104)
at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:66)
at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:58)
at hermes.mediationOrchestrator.AvroFileWriteTest.testWriter3(AvroFileWriteTest.java:115)