ReadRawVarint32()的问题 - Google Protocol Buffers csharp-port

时间:2011-11-02 14:17:16

标签: c# java protocols protocol-buffers protobuf-net

我正在尝试使用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());

任何帮助?

提前致谢。

1 个答案:

答案 0 :(得分:0)

错误消息指出您尝试在不使用对象引用的情况下访问非静态(即成员方法)。您需要更改方法调用以对CodedInputStream类型的对象进行操作,而不是CodedInputStream类:

input.ReadRawVarint32();