I am using the Jon Arch port (excellent) of the Google Protocol protocol port for C # /. Net.
For practice, I wrote an instant messenger app that sends messages over a socket. I have a message definition as follows: -
message InstantMessage {<br/> required string Message = 1;<br/> required int64 TimeStampTicks = 2; <br/> }
When the sender serializes the message, he sends it really elegantly: -
... InstantMessage.Builder imBuild = new InstantMessage.Builder(); imBuild.Message = txtEnterText.Text; imBuild.TimeStampTicks = DateTime.Now.Ticks; InstantMessage im = imBuild.BuildPartial(); im.WriteTo(networkStream); ...
This works great. But on the other hand, itβs hard for me to work ParseFrom .
I want to use: -
InstantMessage im = InstantMessage.ParseFrom(networkStream);
But instead, I had to read it in bytes, and then parse it here. This is obviously not ideal for a number of reasons. Current Code: -
while (true) { Byte[] byteArray = new Byte[10000000]; int intMsgLength; int runningMsgLength = 0; DateTime start = DateTime.Now; while (true) { runningMsgLength += networkStream.Read(byteArray, runningMsgLength, 10000000 - runningMsgLength); if (!networkStream.DataAvailable) break; } InstantMessage im = InstantMessage.ParseFrom(byteArray.Take(runningMsgLength).ToArray());
When I try to use ParseFrom , the control does not return to the calling method even when I know that a valid GB message is on the wire.
Any advice would be greatly appreciated.
Pw
source share