/** * @see igware.protobuf.ProtoChannel#extractMessage(com.google.protobuf.MessageLite.Builder) */ public override void extractMessage(Type type, ref object message) { if (response == null) { response = new MemoryStream(4096); namedPipeWrapper.readBufferFromNamedPipe(response); namedPipeWrapper = null; // Now that we've read the entire response, reset the namedPipeWrapper. response.Position = 0; // Done writing to it. Next, we will read from the beginning. } try { // TODO: we really want this to just be TryDeserializeWithLengthPrefix, but Pedela reported problems when he tried to use it. int msgLen = 0; bool success = ProtoBuf.Serializer.TryReadLengthPrefix(response, ProtoBuf.PrefixStyle.Base128, out msgLen); if (success == false) { throw new protorpc.RpcLayerException(RpcStatus.Status.IO_ERROR, "Failed to read length prefix."); } // Deserialize reads the whole stream. Since 'response' can contain multiple protobufs, we need to // separate out a copy of just the next protobuf. MemoryStream tempInStream = new MemoryStream(response.GetBuffer(), (int)response.Position, msgLen); response.Position += msgLen; message = ProtoBuf.Serializer.NonGeneric.Deserialize(type, tempInStream); } catch (IOException e) { throw new protorpc.RpcLayerException(RpcStatus.Status.IO_ERROR, e.Message); } }