如何定义地图在节俭中接受不同类型的值? [英] how can I define a map accept different kind of value in thrift?

查看:161
本文介绍了如何定义地图在节俭中接受不同类型的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用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,
}

问题是 dataMap ,我不仅要接受 string 值,我可能还是想接受列表 Map ,例如 map< string,list< string>>数据图。换句话说,我想要一个类似Java中的root Object ,python中的 object

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. In other words, I want a type like the root Object in Java, object in python

我可以这样做吗?

推荐答案

你必须创建自己的 Object 并列出其中所有可能的类。

You would have to create your own Object and list all possible classes in it.

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

(因为我不确定工会实施在所有langs中是如何工作的'我d使用带有所有字段的struct可选)

(as I'm not sure how union implementation works in all langs I'd go with struct with all fields optional)

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

然后: map< string,Object>

在Thrift中,您无法创建全部接受字段,因为它无法跨语言完全移植,这是关键功能之一Thrift。

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.

这篇关于如何定义地图在节俭中接受不同类型的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆