|
|
|
|
@ -18,6 +18,11 @@ namespace DotXxlJob.Core |
|
|
|
|
private static readonly Dictionary<string, PropertyInfo> triggerProperties = |
|
|
|
|
new Dictionary<string, PropertyInfo>(); |
|
|
|
|
|
|
|
|
|
private static readonly Dictionary<string, PropertyInfo> responseProperties = |
|
|
|
|
new Dictionary<string, PropertyInfo>(); |
|
|
|
|
|
|
|
|
|
private static readonly Dictionary<string, PropertyInfo> returnProperties = |
|
|
|
|
new Dictionary<string, PropertyInfo>(); |
|
|
|
|
static HessianSerializer() |
|
|
|
|
{ |
|
|
|
|
var typeInfo = typeof(RpcRequest).GetTypeInfo(); |
|
|
|
|
@ -55,6 +60,42 @@ namespace DotXxlJob.Core |
|
|
|
|
|
|
|
|
|
triggerProperties.Add(attribute.Name,property); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var rspTypeInfo = typeof(RpcResponse).GetTypeInfo(); |
|
|
|
|
foreach (var property in rspTypeInfo.DeclaredProperties) |
|
|
|
|
{ |
|
|
|
|
var attribute = property.GetCustomAttribute<DataMemberAttribute>(); |
|
|
|
|
|
|
|
|
|
if (null == attribute) |
|
|
|
|
{ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!property.CanRead || !property.CanWrite) |
|
|
|
|
{ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
responseProperties.Add(attribute.Name,property); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var retTypeInfo = typeof(ReturnT).GetTypeInfo(); |
|
|
|
|
foreach (var property in retTypeInfo.DeclaredProperties) |
|
|
|
|
{ |
|
|
|
|
var attribute = property.GetCustomAttribute<DataMemberAttribute>(); |
|
|
|
|
|
|
|
|
|
if (null == attribute) |
|
|
|
|
{ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!property.CanRead || !property.CanWrite) |
|
|
|
|
{ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
returnProperties.Add(attribute.Name,property); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static RpcRequest DeserializeRequest(Stream stream) |
|
|
|
|
@ -87,7 +128,11 @@ namespace DotXxlJob.Core |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
if (item.Item2 is HessianObject ) |
|
|
|
|
if (item.Item1 == "parameterTypes") |
|
|
|
|
{ |
|
|
|
|
request.ParameterTypes = item.Item2 as List<object>; |
|
|
|
|
} |
|
|
|
|
else if (item.Item2 is HessianObject ) |
|
|
|
|
{ |
|
|
|
|
request.Parameters = new List<object>(); |
|
|
|
|
|
|
|
|
|
@ -100,7 +145,7 @@ namespace DotXxlJob.Core |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
throw new HessianException($"unknown item :{item.Item1}"); |
|
|
|
|
throw new HessianException($"unknown item :{item.Item1},{item.Item2.GetType()}"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -175,7 +220,7 @@ namespace DotXxlJob.Core |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (typeof (String) == typeInfo.AsType()) |
|
|
|
|
if (typeof (string) == typeInfo.AsType()) |
|
|
|
|
{ |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
@ -185,7 +230,76 @@ namespace DotXxlJob.Core |
|
|
|
|
|
|
|
|
|
public static RpcResponse DeserializeResponse(Stream resStream) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
var rsp = new RpcResponse(); |
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
var deserializer = new Deserializer(resStream); |
|
|
|
|
var classDef = deserializer.ReadValue() as ClassDef; |
|
|
|
|
if (!Constants.RpcResponseJavaFullName.Equals(classDef.Name)) |
|
|
|
|
{ |
|
|
|
|
throw new HessianException($"unknown class :{classDef.Name}"); |
|
|
|
|
} |
|
|
|
|
if (responseProperties.Count != classDef.Fields.Length) |
|
|
|
|
{ |
|
|
|
|
throw new HessianException($"unknown class :{classDef.Name}, field count not match ${responseProperties.Count} !={classDef.Fields.Length}"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//obj serialize |
|
|
|
|
if (deserializer.ReadValue() is HessianObject hessianObject) |
|
|
|
|
{ |
|
|
|
|
foreach (var item in hessianObject) |
|
|
|
|
{ |
|
|
|
|
if (responseProperties.TryGetValue(item.Item1, out var p)) |
|
|
|
|
{ |
|
|
|
|
if (IsSimpleType(p.PropertyType.GetTypeInfo())) |
|
|
|
|
{ |
|
|
|
|
p.SetValue(rsp,item.Item2); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
if (item.Item2 is ClassDef resultClassDef ) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
//TODO:这里要做成动态的话 ,可以注册所有的实体到对应的字典中,不过这里只有这个类型哦 |
|
|
|
|
if (resultClassDef.Name != "com.xxl.job.core.biz.model.ReturnT") |
|
|
|
|
{ |
|
|
|
|
throw new HessianException($"not expected parameter type [{resultClassDef.Name}]"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!(deserializer.ReadValue() is HessianObject resultData)) |
|
|
|
|
{ |
|
|
|
|
throw new HessianException("not expected parameter type ,data is null"); |
|
|
|
|
} |
|
|
|
|
ReturnT data = new ReturnT(); |
|
|
|
|
foreach (var field in resultData) |
|
|
|
|
{ |
|
|
|
|
if (returnProperties.TryGetValue(field.Item1, out var tgPropertyInfo)) |
|
|
|
|
{ |
|
|
|
|
tgPropertyInfo.SetValue(data,field.Item2); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
rsp.Result = data; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
throw new HessianException($"unknown item :{item.Item1},{item.Item2.GetType()}"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
catch (EndOfStreamException) |
|
|
|
|
{ |
|
|
|
|
//没有数据可读了 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return rsp; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|