- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在阅读 Netty 教程时,我发现了一个简单的 description如何集成 Netty 和 Google Protocol Buffers .我已经开始研究它的示例(因为文档中没有更多信息)并编写了一个简单的应用程序,如示例本地时间应用程序。但是这个例子是在 PipeFactory 类中使用静态初始化,例如:
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.handler.codec.protobuf.ProtobufDecoder;
import org.jboss.netty.handler.codec.protobuf.ProtobufEncoder;
import org.jboss.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
import org.jboss.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;
import static org.jboss.netty.channel.Channels.pipeline;
/**
* @author sergiizagriichuk
*/
class ProtoCommunicationClientPipeFactory implements ChannelPipelineFactory {
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline p = pipeline();
p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
p.addLast("protobufDecoder", new ProtobufDecoder(Communication.DataMessage.getDefaultInstance()));
p.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender());
p.addLast("protobufEncoder", new ProtobufEncoder());
p.addLast("handler", new ProtoCommunicationClientHandler());
return p;
}
}
(请查看行 p.addLast("protobufDecoder", new ProtobufDecoder(Communication.DataMessage.getDefaultInstance()));
)并且只能为 ClientBootstrap
类创建一个工厂(据我所知),我的意思是 bootstrap.setPipelineFactory()
方法。所以,在这种情况下,我可以使用 ONE 消息发送到服务器,并使用 ONE 消息从服务器接收,这对我不利,而且我认为不仅仅是对我而言: (我怎样才能为一个连接使用不同的消息来回?也许我可以像这样创建一些 protobufDecoder
p.addLast("protobufDecoder", new ProtobufDecoder(Communication.DataMessage.getDefaultInstance()));
p.addLast("protobufDecoder", new ProtobufDecoder(Communication.TestMessage.getDefaultInstance()));
p.addLast("protobufDecoder", new ProtobufDecoder(Communication.SrcMessage.getDefaultInstance()));
或其他技术?非常感谢。
最佳答案
我在 google groups 中找到了 netty 作者的帖子并且明白我必须像上面写的那样改变我的架构或编写我自己的解码器,所以,开始思考什么方法会更简单更好。
关于java - Netty + ProtoBuffer : A few communication messages for one connection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7803966/
我正在使用 protobuf-csharp-port 库以文本形式写入和读取消息。 我可以使用以下代码以文本形式编写消息,但我找不到任何示例来说明如何将此消息读回到原型(prototype) buff
在尝试使用以下命令编译名为 UserOptions.proto 的 proto 文件时,该文件具有名为 Account.proto 的导入 protoc --proto_path=/home/proj
考虑以下消息。 message example { repeated string text; } 假设在 C++ 中,我将一个字符串列表插入到示例的文本字段中: exemple aMessag
我正在研究从数据库中获取数据并构造 protobuff 消息的东西。鉴于可以从数据库中为某些字段获取空值的可能性,我将在尝试构造 protobuff 消息时得到空指针异常。从线程 http://cod
我遇到了错误 The type cannot be changed once a serializer has been generated 尝试使用 Protobuff.net 进行序列化时。我已设
我有一个 protoBuff3 规范,看起来像 message MSG { string name = 1; repeated string data = 2; } 还有一个设置“MSG.
自从我注意到 MapStruct 已更新以与 Protobuff 及其构建器交互,我考虑迁移我们的服务以完全使用 MapStruct。 然而,我们仍在编写到 protobuff 消息的手动转换,因为考
为什么 ProtoBuff.Net 不支持null? 我正在浏览 ProtoBuf,想知道为什么不支持 null 值。当我们尝试分配 null 值时,它给出了异常。即使像字符串这样的 ref 也不支持
我正在使用 Squareup Wire protobuf 生成 protobuf 类图书馆 这是我的原型(prototype)文件 syntax = "proto2"; package squareu
我正在实现一个自定义协议(protocol),两个应用程序将使用该协议(protocol)相互发送各种命令(包括文件传输,即大型二进制数据 block )。经过深思熟虑,我认为 protobuff 是
我创建了一个原型(prototype)插件。当我执行时: $ protoc --plugin=protoc-gen-grpc-java=grpc-client-guice-gradle-plugin
是否可以将 grpc 中 proto3 的默认模型从 CamelCase 更改为 snake_case? 例子: 文件 anyproto.proto ... message Request { b
总结:使用新的 tf.contrib.data.Dataset 使我的图形 protobuff 文件的大小加倍,我无法在 Tensorboard 中可视化图形。 详情: 我正在试用新的 TensorF
在阅读 Netty 教程时,我发现了一个简单的 description如何集成 Netty 和 Google Protocol Buffers .我已经开始研究它的示例(因为文档中没有更多信息)并编写
正在开发一个使用 ProtoBuff 获取其内容的项目。通过在 HTML 中加载 JavaScript 使其工作一次。现在重构为使用 requirejs 来加载脚本。但是当我尝试使用脚本时,它给出一个
我有一个简单的原型(prototype)文件,用于创建我的 java 类 syntax = "proto3"; option java_package = "some.project.grpc"; o
我正在调用一个 api 来获取输入流,然后调用静态方法 parseFrom(inputstream) 将其转换为 protobuffclass。 如果我用一个特定的类来做它会起作用: public C
我们有一个使用 google 实现的 java 后端表面原型(prototype)对象。我们现在想在客户端使用 .net 中的这些对象并对其进行操作。问题是我们不想在客户端依赖谷歌的不可变原型(pro
我是 c++ 和 visual studio 2012 的新手,所以问题可能出在屏幕和椅子之间。我执行了以下步骤; 我制作了一个带有选项 optimize_for = LITE_RUNTIME 的简单
使用 Protocol Buffer 对象(序列化为字节数组)在 Android Activity 之间作为 intent extras 传递而不是在经典 POJO 上实现 Parcelable 是个
我是一名优秀的程序员,十分优秀!