Пример #1
0
        static internal void OnCallCompleted(
            RcfProtoChannel self)
        {
            // Deserialize the response
            int requestBufferLen = self._GetResponseBufferLength();

            if (requestBufferLen == 0)
            {
                // Get crashes from Google.ProtocolBuffers.dll if we pass in null.
                //Google.ProtocolBuffers.IMessage response = null;
                self.mResponse = self.mResponsePrototype.WeakDefaultInstanceForType;
            }
            else
            {
                // Deserialize response.
                byte[] requestBuffer = new byte[requestBufferLen];
                self._GetResponseBuffer(requestBuffer, requestBufferLen);
                Google.ProtocolBuffers.IBuilder   builder    = self.mResponsePrototype.WeakCreateBuilderForType();
                Google.ProtocolBuffers.ByteString byteString = Google.ProtocolBuffers.ByteString.CopyFrom(requestBuffer);
                builder.WeakMergeFrom(byteString);
                self.mResponse = builder.WeakBuild();
            }

            bool asyncRpc = self.GetAsynchronousRpcMode();

            if (asyncRpc)
            {
                self.mDone(self.mResponse);
            }
        }
Пример #2
0
        static internal void CallMethod(
            RcfProtoChannel self,
            Google.ProtocolBuffers.Descriptors.MethodDescriptor method,
            Google.ProtocolBuffers.IRpcController controller,
            Google.ProtocolBuffers.IMessage request,
            Google.ProtocolBuffers.IMessage responsePrototype,
            Action <Google.ProtocolBuffers.IMessage> done)
        {
            self.mResponse      = null;
            self.mResponseError = null;

            self.mDone = done;
            self.mResponsePrototype = responsePrototype;

            // Serialize the request.
            RcfProtoController rcfController = (RcfProtoController)controller;

            if (rcfController != null)
            {
                rcfController.Reset();
                rcfController.mChannel = self;
            }

            string serviceName = method.Service.Name;
            int    methodId    = method.Index;

            byte[] bytes = request.ToByteArray();

            // Hand off to RCF.
            if (self.mSwigCallback == null)
            {
                self.mSwigCallback = new SwigCallback_CallCompletion(self);
            }
            self._CallMethodSwig(serviceName, methodId, bytes, bytes.Length, self.mSwigCallback);

            bool syncRpc = !self.GetAsynchronousRpcMode();

            if (syncRpc)
            {
                if (self.Failed())
                {
                    self.mResponseError = self.ErrorText();
                    throw new System.Exception(self.mResponseError);
                }
            }
        }