ReadRawVarint32() 的问题 - Google Protocol Buffers csharp-port
我正在尝试使用 Google Protocol Buffers(具体来说,Jon Skeet 的 csharp-port)从服务器中的客户端接收一些数据。我执行以下操作:
using Google.ProtocolBuffers;
...
Stream InputStream = client.GetStream();
CodedInputStream input = CodedInputStream.CreateInstance(InputStream);
...
uint length = CodedInputStream.ReadRawVarint32(InputStream);
我从最后一行收到一条无法解决的错误消息:需要对象引用才能访问非静态成员“Google.ProtocolBuffers.CodedInputStream.ReadRawVarint32()”。
基本上我想做的在java版本中是这样的:
InputStream iStream = client.getInputStream();
CodedInputStream input = CodedInputStream.newInstance(iStream);
int read = is.read();
if(-1 != read) {
int length = CodedInputStream.readrawVarint32(read, is);
byte[] bytes = input.readRawBytes(length);
// My proto stuff
Communication.Packet container = null;
try {
container = Communication.Packet.parseFrom(bytes);
} catch (InvalidProtocolBufferException iPBE) {
continue;
}
AbstractMessage message = container;
if(container.hasLogin()) {
message = container.getLogin();
}
System.out.println(message.toString());
有帮助吗?
提前致谢。
I'm trying to receive some data from a client in a server using Google Protocol Buffers, concretely, Jon Skeet's csharp-port. I do the following:
using Google.ProtocolBuffers;
...
Stream InputStream = client.GetStream();
CodedInputStream input = CodedInputStream.CreateInstance(InputStream);
...
uint length = CodedInputStream.ReadRawVarint32(InputStream);
I get an error message from the last line which i cannot solve: An object reference is requiered to access non-static member 'Google.ProtocolBuffers.CodedInputStream.ReadRawVarint32()'.
Basicly what i want to do would be like this in the java version:
InputStream iStream = client.getInputStream();
CodedInputStream input = CodedInputStream.newInstance(iStream);
int read = is.read();
if(-1 != read) {
int length = CodedInputStream.readrawVarint32(read, is);
byte[] bytes = input.readRawBytes(length);
// My proto stuff
Communication.Packet container = null;
try {
container = Communication.Packet.parseFrom(bytes);
} catch (InvalidProtocolBufferException iPBE) {
continue;
}
AbstractMessage message = container;
if(container.hasLogin()) {
message = container.getLogin();
}
System.out.println(message.toString());
Any help?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该错误消息表明您正在尝试访问非静态(即成员方法)而不使用对象引用。您需要更改方法调用以对 CodedInputStream 类型的对象而不是 CodedInputStream 类进行操作:
input.ReadRawVarint32();
The error message states that you are trying to access a non-static (i.e. a member method) without using an object reference. You need to change your method call to operate on the object of type CodedInputStream instead of the CodedInputStream class:
input.ReadRawVarint32();