Skip to content

Commit

Permalink
build(copy) to unity
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Sep 9, 2019
1 parent cbf33db commit 1bb8a70
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public abstract class RequestContext
public Type ResponseType { get; }
public abstract Type RequestType { get; }
public Func<byte[], byte[]> RequestMutator { get; private set; }
public Func<byte[], byte[]> ResponseMutator { get; private set; }

Dictionary<string, object> items;
public IDictionary<string, object> Items
Expand Down Expand Up @@ -49,12 +50,18 @@ internal RequestContext(MagicOnionClientBase client, string methodPath, CallOpti
this.Filters = filters;
this.RequestMethod = requestMethod;
this.RequestMutator = DefaultMutator;
this.ResponseMutator = DefaultMutator;
}

public void SetRequestMutator(Func<byte[], byte[]> mutator)
{
this.RequestMutator = mutator;
}

public void SetResponseMutator(Func<byte[], byte[]> mutator)
{
this.ResponseMutator = mutator;
}
}

public class RequestContext<T> : RequestContext
Expand Down Expand Up @@ -100,7 +107,7 @@ public ResponseContext()
this.ResponseMutator = DefaultMutator;
}

public void SetRequestMutator(Func<byte[], byte[]> mutator)
public void SetResponseMutator(Func<byte[], byte[]> mutator)
{
this.ResponseMutator = mutator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ static protected ResponseContext CreateResponseContext<TResponse>(RequestContext
{
var self = context.Client;
var callResult = self.callInvoker.AsyncUnaryCall(method, self.host, context.CallOptions, context.RequestMutator(MagicOnionMarshallers.UnsafeNilBytes));
return new ResponseContext<TResponse>(callResult, self.resolver);
var response = new ResponseContext<TResponse>(callResult, self.resolver);
response.SetResponseMutator(context.ResponseMutator);
return response;
}

static protected ResponseContext CreateResponseContext<TRequest, TResponse>(RequestContext context, Method<byte[], byte[]> method)
{
var self = context.Client;
var message = LZ4MessagePackSerializer.Serialize<TRequest>(((RequestContext<TRequest>)context).Request, self.resolver);
var callResult = self.callInvoker.AsyncUnaryCall(method, self.host, context.CallOptions, context.RequestMutator(message));
return new ResponseContext<TResponse>(callResult, self.resolver);
var response = new ResponseContext<TResponse>(callResult, self.resolver);
response.SetResponseMutator(context.ResponseMutator);
return response;
}
}

Expand Down

0 comments on commit 1bb8a70

Please sign in to comment.