所有教程和文档都建议每个Thrift服务器可以提供一个服务(1个处理程序1个处理器1服务器,所有服务器都在构造函数中提供).
从我的观点来看(设计的优雅),如果许多或所有服务定义可以是独立的,那就更好了.
我已经为我的库和服务器安装了thrift; 使用NuGet.
我有一个非常简单的thrift文件,我使用以下命令编译它:
thrift.exe -r --gen csharp node.thrift
node.thrift有三行:
service Server {
string ping()
}
Run Code Online (Sandbox Code Playgroud)
我从thrift编译器生成的Server.cs中获取错误.
'TProtocol'不包含'IncrementRecursionDepth'的定义
抛出错误的示例行:
public void Read (TProtocol iprot)
{
iprot.IncrementRecursionDepth(); //this line has the error
Run Code Online (Sandbox Code Playgroud)
我用Google搜索了,但没有找到任何结果.
更新:如果我删除抛出错误的行,库编译并且服务器按预期工作,我不知道将来是否会遇到错误,最后是递归吗?!
重要的一点:我使用我下载的可执行文件编译thrift文件http://www.apache.org/dyn/closer.cgi?path=/thrift/0.9.3/thrift-0.9.3.exe.版本是0.9.3但NuGet安装的thrift库是0.9.1.3
我已经看到几个消息源声明Thrift是一种二进制通信协议(例如,其Wikipedia文章的第一行)。
但是,Thrift可以通过http进行调用,我认为这是基于文本的协议,而不是二进制协议。
也许消息人士只是说Thrift有可用的二进制协议选项,但也有诸如http的选项?
我意识到我可能在节俭的背景下误解了“协议”的含义。例如,使用TJsonProtocol选项对数据进行JSON编码,是否可以通过http以及二进制协议发送数据?
如果我滥用任何术语,我深表歉意,我认为这可能会加剧我的困惑。不幸的是,我不是OSI模型的专家。
我通过thrift协议从c ++后端获取一些信息,包含带有德语变音符号的字符串(名称).现在这些变音符号显示为问号,所以我认为我正在尝试将它们转换为utf-8,尽管thrift似乎传递字符串为utf-8无论如何.
原始数据来自postgresql数据库,并在将其发送到thrift接口之前正确显示在c ++代码中.
我已经尝试了3种不同的版本进行转换,但它们都没有真正做任何事情我被困在这里.
版本1:
private string ConvertUTF8(string str) // str == "Ha?loch, ?mely"
{
byte[] bytSrc;
byte[] bytDestination;
string strTo = string.Empty;
bytSrc = Encoding.Unicode.GetBytes(str);
bytDestination = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, bytSrc);
strTo = Encoding.UTF8.GetString(bytDestination);
return strTo; // strTo == "Ha?loch, ?mely"
}
Run Code Online (Sandbox Code Playgroud)
版本2:
private string ConvertUTF8(string str) // str == "Ha?loch, ?mely"
{
byte[] bytes = str.Select(c => (byte)c).ToArray();
return Encoding.UTF8.GetString(bytes); // == "Ha?loch, ?mely"
}
Run Code Online (Sandbox Code Playgroud)
版本3:
private string ConvertUTF8(string str) // str == "Ha?loch, ?mely"
{
byte[] bytes …Run Code Online (Sandbox Code Playgroud) 如果客户端不再使用字段,则通过重命名来弃用 Thrift 中的字段是否安全?我的理解是,只要我们不更改类型,这应该有效。例如
从
struct FooResponse {
1: optional i32 foo
}
Run Code Online (Sandbox Code Playgroud)
到
struct FooResponse {
1: optional i32 fooDeprecated
}
Run Code Online (Sandbox Code Playgroud)