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.
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();