Exemplo n.º 1
0
        internal static object QueryInternal(this FastRpcClient fastRpcClient, string title, ICustomTuple customTuple, Type returnType, IRpcSerializer rpcSerializer, string extention = null, bool throwIfErrorResponseCode = false)
        {
            if (rpcSerializer == null)
            {
                throw new ArgumentNullException(nameof(rpcSerializer));
            }

            if (customTuple == null)
            {
                throw new ArgumentNullException(nameof(customTuple));
            }

            var encoding = RpcExtentionSettings.DefaultEncoding;

            var response = fastRpcClient.Query(
                encoding.GetBytes(title),
                encoding.GetBytes(rpcSerializer.Serialize(customTuple)),
                extention == null ? FrameFormat.EmptyBytes : encoding.GetBytes(extention),
                throwIfErrorResponseCode);

            if (returnType == typeof(void))
            {
                return(null);
            }

            var responseContent = response.ReadContentString();

            if (string.IsNullOrEmpty(responseContent))
            {
                return(null);
            }

            return(rpcSerializer.Deserialize(responseContent, returnType));
        }
        internal static object QueryInternal(this FastRpcClient fastRpcClient, string title, ICustomTuple customTuple, Type returnType, IBinarySerializer serializer, string extention = null, bool throwIfErrorResponseCode = true)
        {
            if (serializer == null)
            {
                throw new ArgumentNullException(nameof(serializer));
            }

            if (customTuple == null)
            {
                throw new ArgumentNullException(nameof(customTuple));
            }

            var encoding = NetworkSettings.TitleExtentionEncoding;

            var response = fastRpcClient.Query(
                encoding.GetBytes(title),
                serializer.Serialize(customTuple),
                extention == null ? FrameFormat.EmptyBytes : encoding.GetBytes(extention),
                throwIfErrorResponseCode);

            if (returnType == typeof(void))
            {
                return(null);
            }

            if (response.ContentBytes == null)
            {
                return(null);
            }

            return(serializer.Deserialize(response.ContentBytes, returnType));
        }