ReadRawVarint32()的问题-谷歌协议缓冲csharp-port
本文关键字:谷歌 协议 缓冲 csharp-port 问题 ReadRawVarint32 | 更新日期: 2023-09-27 18:13:01
我试图从使用谷歌协议缓冲区的服务器中的客户端接收一些数据,具体来说,是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());
帮忙吗?
错误消息指出您正在尝试访问非静态(即成员方法)而不使用对象引用。您需要更改方法调用,以操作CodedInputStream类型的对象,而不是CodedInputStream类:
input.ReadRawVarint32();