简体   繁体   English

如何定义地图可以在节俭中接受其他类型的价值?

[英]how can I define a map accept different kind of value in thrift?

I define a struct with thrift: 我用节俭定义了一个结构:

struct QuerySetRecord {
    1:string recordId,
    2:string crawlerName,
    3:string recordType,
    4:map<string,string> dataMap,
    5:i16 priority,
}

the problem is the dataMap , I do not only want to accept string value, I may still want to accept List or Map , such as map<string, list<string>> dataMap . 问题是dataMap ,我不仅要接受string值,我可能仍想接受ListMap ,例如map<string, list<string>> dataMap In other words, I want a type like the root Object in Java, object in python 换句话说,我想要一个类型,例如Java中的root Object ,Python中的object

Can I do this? 我可以这样做吗?

You would have to create your own Object and list all possible classes in it. 您将必须创建自己的Object并列出其中的所有可能的类。

union Object {
   1: string str;
   2: i32 number32;
}

(as I'm not sure how union implementation works in all langs I'd go with struct with all fields optional) (因为我不确定在所有语言中联合实现的工作方式,我会选择带有所有字段可选的struct)

struct Object {
   1: optional string str;
   2: optional i32 number32;
}

and then: map<string, Object> 然后: map<string, Object>

In Thrift you can't create 'accept all' field, as it could not be fully portable across languages, and that's one of key functionalities of Thrift. 在Thrift中,您无法创建“ accept all”(全部接受)字段,因为它不能跨语言完全移植,这是Thrift的主要功能之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM