我有一个avro
架构和avro
我希望将其推入一个protobuf。
具体来说,我有两个变量:
1 - Schema myschema; (this is the avro schema in the org.apache.avro)
2- Map<Long, Schema> myschemamap (this is a map containing a long of schema objects)
protobuf不支持“schema”和“map”,但看起来它支持“bytes”。我最简单的方法是将这两个不同的变量推入protobuf中的两个不同的字段,并将它们“deserilize”回原来的Schema和Map对象上面?
答案 0 :(得分:0)
一个非常简单的解决方案(尽管当然不是最快或最节省空间的)是使用JSON representation of the Schema并将其存储在protobuf的字符串字段中。你是正确的,protobufs中没有地图,但你可以迭代地图并保存每个条目。然后通过迭代重复字段的每个条目并重建Map来反序列化。这是您可以使用的protobuf定义:
message SchemaHolder {
optional string schema = 1;
repeated MapEntry schema_map = 2;
}
message MapEntry {
optional int64 key = 1;
optional string value = 2;
}