我正在使用Avro C++库。我有一个使用“decode”函数获得的二进制对象和一个字节流作为源。我需要将其转换为JSON字符串,对象模式可用。有办法做到这一点吗?我找不到示例。
kadbb4591#
解决方法:
ObjectType Object; std::unique_ptr<avro::InputStream> ObjectInputStream = avro::memoryInputStream((uint8_t *)PointerToBinaryData, BinaryDataSize); avro::DecoderPtr Decoder = avro::binaryDecoder(); Decoder->init(*ObjectInputStream); avro::decode(*Decoder, Object); std::ifstream SchemaFile("/path_to_the_schema/schema_file.avsc"); avro::ValidSchema Schema; avro::compileJsonSchema(SchemaFile, Schema); std::unique_ptr<avro::OutputStream> JsonOutputFile = avro::fileOutputStream("path_to_json_file/json_file.json"); avro::EncoderPtr JsonEncoder = avro::jsonPrettyEncoder(Schema); JsonEncoder->init(*JsonOutputFile); avro::encode(*JsonEncoder, Object); JsonEncoder->flush();
字符串
1条答案
按热度按时间kadbb4591#
解决方法:
字符串