完成传输对象的序列化和反序列化

pull/1/head
假正经哥哥 7 years ago
parent 2d2dac9cb3
commit 537c909dfc
  1. 5
      samples/ASPNetCoreExecutor/Startup.cs
  2. 2
      samples/ASPNetCoreExecutor/appsettings.json
  3. 77
      samples/HessianReader/NewFile1.txt
  4. 74
      samples/HessianReader/NewFile2.txt
  5. 63
      samples/HessianReader/Program.cs
  6. BIN
      samples/HessianReader/request.dat
  7. 15
      src/DotXxlJob.Core/AdminClient.cs
  8. 12
      src/DotXxlJob.Core/DefaultHandlers/HttpJobHandler.cs
  9. 41
      src/DotXxlJob.Core/DefaultJobHandlerFactory.cs
  10. 8
      src/DotXxlJob.Core/Extensions/ServiceCollectionExtensions.cs
  11. 2
      src/DotXxlJob.Core/Internal/Constants.cs
  12. 126
      src/DotXxlJob.Core/Internal/HessianObjectConvert.cs
  13. 246
      src/DotXxlJob.Core/Internal/HessianSerializer.cs
  14. 2
      src/DotXxlJob.Core/Model/AddressEntity.cs
  15. 2
      src/DotXxlJob.Core/Model/RegistryParam.cs
  16. 2
      src/DotXxlJob.Core/Model/RpcResponse.cs
  17. 70
      src/Hessian.NET/DataContractHessianSerializer.cs
  18. 54
      src/Hessian.NET/DisposableStreamHandler.cs
  19. 56
      src/Hessian.NET/Extension/DateTimeExtension.cs
  20. 75
      src/Hessian.NET/Extension/Maybe.cs
  21. 7
      src/Hessian.NET/Hessian.NET.csproj
  22. 664
      src/Hessian.NET/HessianInputReader.cs
  23. 45
      src/Hessian.NET/HessianObjectSerializerFactory.cs
  24. 128
      src/Hessian.NET/HessianObjectWriterFactory.ObjectWriters.cs
  25. 321
      src/Hessian.NET/HessianOutputWriter.cs
  26. 27
      src/Hessian.NET/HessianSerializationContext.cs
  27. 127
      src/Hessian.NET/HessianSerializationScheme.cs
  28. 9
      src/Hessian.NET/HessianSerializerException.cs
  29. 13
      src/Hessian.NET/HessianSerializerSettings.cs
  30. 9
      src/Hessian.NET/IObjectSerializer.cs
  31. 9
      src/Hessian.NET/IObjectSerializerFactory.cs
  32. 16
      src/Hessian.NET/ISerializationElement.cs
  33. 162
      src/Hessian.NET/LeadingByte.cs
  34. 179
      src/Hessian.NET/ListElement.cs
  35. 66
      src/Hessian.NET/ListTypeResolver.cs
  36. 42
      src/Hessian.NET/Marker.cs
  37. 153
      src/Hessian.NET/ObjectElement.cs
  38. 17
      src/Hessian.NET/ObjectPreamble.cs
  39. 23
      src/Hessian.NET/ObjectPropertyComparer.cs
  40. 71
      src/Hessian.NET/PropertyElement.cs
  41. 15
      src/Hessian.NET/Specification/AndSpecification.cs
  42. 25
      src/Hessian.NET/Specification/BinarySpecification.cs
  43. 16
      src/Hessian.NET/Specification/ISpecification.cs
  44. 17
      src/Hessian.NET/Specification/NotSpecification.cs
  45. 29
      src/Hessian.NET/Specification/OrSpecification.cs
  46. 19
      src/Hessian.NET/Specification/Specification.cs
  47. 32
      src/Hessian.NET/Specification/SpecificationExtension.cs
  48. 23
      src/Hessian.NET/Throw.cs
  49. 10
      src/Hessian.NET/TypeResolver.cs
  50. 33
      src/Hessian.NET/ValueElement.cs
  51. 140
      src/Hessian/Deserializer.cs
  52. 6
      src/Hessian/Serializer.cs

@ -22,12 +22,13 @@ namespace ASPNetCoreExecutor
{
services.AddXxlJobExecutor(Configuration);
services.AddDefaultXxlJobHandlers();// add httpHandler;
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app,ILoggerFactory loggerFactory, IHostingEnvironment env)
public void Configure(IApplicationBuilder app,ILoggingBuilder loggerBuilder, IHostingEnvironment env)
{
loggerFactory.AddConsole();
loggerBuilder.AddConsole();
if (env.IsDevelopment())
{

@ -5,7 +5,7 @@
}
},
"xxlJob": {
"adminAddresses":"http://127.0.0.1:8101",
"adminAddresses":"http://127.0.0.1:8080",
"appName": "ASPNetCoreExecutor",
"port": 5000,
"accessToken": "",

@ -3,70 +3,71 @@ ReadClassDefinition
Hessian.ClassDef={"Name":"com.xxl.rpc.remoting.net.params.XxlRpcRequest","Fields":["requestId","createMillisTime","accessToken","className","methodName","version","parameterTypes","parameters"]}
------------------------------------------------------------
------------ 0x60----------------
ReadObjectCompact
------------ 0x00----------------
ReadShortString requestId
ReadObjectCompact XxlRpcRequest
------------ 0x30----------------
ReadMediumString requestId
------------ 0x4c----------------
ReadLongFull createMillisTime
------------ 0x00----------------
ReadShortString accessToken
ReadLongFull createMillisTime
------------ 0x00----------------
ReadShortString className
ReadShortString accessToken
------------ 0x1d----------------
ReadShortString className
------------ 0x08----------------
ReadShortString methodName
ReadShortString methodName
------------ 0x4e----------------
ReadNull version
ReadNull version
------------ 0x71----------------
ReadCompactFixList parameterTypes
------------ 0x43----------------
ReadClassDefinition
ReadClassDefinition java.lang.Class
------------ 0x61----------------
ReadObjectCompact
ReadObjectCompact java.lang.Class
------------ 0x0e----------------
ReadShortString
Hessian.HessianObject=[{"Item1":"requestId","Item2":""},{"Item1":"createMillisTime","Item2":1547809331509},{"Item1":"accessToken","Item2":""},{"Item1":"className","Item2":""},{"Item1":"methodName","Item2":"callback"}
,{"Item1":"version","Item2":null},{"Item1":"parameterTypes","Item2":[{"Name":"java.lang.Clas
s","Fields":["name"]}]},{"Item1":"parameters","Item2":[{"Item1":"name","Item2":"java.util.List"}]}]
ReadShortString name
Hessian.HessianObject=[{"Item1":"requestId","Item2":"e24123be4a76417ca6f41f227532b235"},{"Item1":"createMillisTime","Item2":1547819469003},{"Item1":"accessToken","Item2":""},{"Item1":"className","Item2":"com.xxl.job.core.biz.AdminBiz"},{"It
em1":"methodName","Item2":"callback"},{"Item1":"version","Item2":null},{"Item1":"parameterTypes","Item2":[{"Name":"java.lang.Class","Fields":["name"]}]},{"Item1":"parameters","Item2":[{"Item1":"name","Item2":"java.util.List"}]}]
------------------------------------------------------------
------------ 0x71----------------
ReadCompactFixList parameters
------------ 0x72----------------
ReadCompactFixList List
ReadCompactFixList List
------------ 0x43----------------
ReadClassDefinition HandleCallbackParam
------------ 0x62----------------
ReadObjectCompact HandleCallbackParam
------------ 0xcc----------------
ReadIntegerTwoBytes logId
ReadObjectCompact HandleCallbackParam
------------ 0x9b----------------
ReadIntegerSingleByte logId
------------ 0x4c----------------
ReadLongFull logDateTim
------------ 0x43----------------
ReadClassDefinition executeResult
System.Collections.Generic.List`1[System.Object]=[{"Name":"com.xxl.job.core.biz.model.HandleCallbackParam","Fields":["logId","logDateTim","executeResult"]},[{"Item1":"logId","Item2":1111},{"Item1":"logDateTim","Item2":1547809331507},{"Item1":"executeResult","Item2":{"Name":"com.xxl.job.core.biz.model.Return
T","Fields":["code","msg","content"]}}]]
ReadClassDefinition executeResult
System.Collections.Generic.List`1[System.Object]=[[{"Name":"com.xxl.job.core.biz.model.HandleCallbackParam","Fields":["logId","logDateTim","executeResult"]},[{"Item1":"logId","Item2":11},{"Item1":"logDateTim","Item2":1547819469000},{"Item1"
:"executeResult","Item2":{"Name":"com.xxl.job.core.biz.model.ReturnT","Fields":["code","msg","content"]}}]]]
------------------------------------------------------------
------------ 0x63----------------
ReadObjectCompact ReturnT
ReadObjectCompact executeResult
------------ 0xc8----------------
ReadIntegerTwoBytes code
------------ 0x4e----------------
ReadNull msg
------------ 0x03----------------
ReadShortString msg
------------ 0x07----------------
ReadShortString aaaaaaa
Hessian.HessianObject=[{"Item1":"code","Item2":200},{"Item1":"msg","Item2":null},{"Item1":"content","Item2":"aaaaaaa"}]
ReadShortString content
Hessian.HessianObject=[{"Item1":"code","Item2":200},{"Item1":"msg","Item2":"1bc"},{"Item1":"content","Item2":"acd3323"}]
------------------------------------------------------------
------------ 0x62----------------
ReadObjectCompact HandleCallbackParam
------------ 0xd7----------------
ReadIntegerThreeBytes logId
ReadObjectCompact HandleCallbackParam
------------ 0xa6----------------
ReadIntegerSingleByte logId
------------ 0x4c----------------
ReadLongFull logDateTim
ReadLongFull logDateTim
------------ 0x63----------------
ReadObjectCompact executeResult
------------ 0xc8----------------
------------ 0xc9----------------
ReadIntegerTwoBytes code
------------ 0x4e----------------
ReadNull msg
------------ 0x06----------------
ReadShortString content
Hessian.HessianObject=[{"Item1":"logId","Item2":222222},{"Item1":"logDateTim","Item2":1547809331507},{"Item1":"executeResult","Item2":[{"Item1":"code","Item2":200},{"Item1":"msg","Item2":null},{"Item1":"content","Item2":"bbbbbb"}]}]
------------ 0x03----------------
ReadShortString msg
------------ 0x03----------------
ReadShortString content
Hessian.HessianObject=[{"Item1":"logId","Item2":22},{"Item1":"logDateTim","Item2":1547819469000},{"Item1":"executeResult","Item2":[{"Item1":"code","Item2":500},{"Item1":"msg","Item2":"cac"},{"Item1":"content","Item2":"aad"}]}]
------------------------------------------------------------
------------------------------------------------------------

@ -0,0 +1,74 @@
---------------------------------------------------------------
------------ 0x43----------------
ReadClassDefinition
Hessian.ClassDef={"Name":"com.xxl.rpc.remoting.net.params.XxlRpcRequest","Fields":["requestId","createMillisTime","accessToken","className","methodName","version","parameterTypes","parameters"]}
------------------------------------------------------------
------------ 0x60----------------
ReadObjectCompact
------------ 0x30----------------
ReadMediumString
------------ 0x4c----------------
ReadLongFull
------------ 0x00----------------
ReadShortString
------------ 0x1d----------------
ReadShortString
------------ 0x08----------------
ReadShortString
------------ 0x4e----------------
ReadNull
------------ 0x71----------------
ReadCompactFixList
------------ 0x43----------------
ReadClassDefinition
------------ 0x61----------------
ReadObjectCompact
------------ 0x0e----------------
ReadShortString
Hessian.HessianObject=[{"Item1":"requestId","Item2":"e24123be4a76417ca6f41f227532b235"},{"Item1":"createMillisTime","Item2":1547819469003},{"Item1":"accessToken","Item2":""},{"Item1":"className","Item2":"com.xxl.job.core.biz.AdminBiz"},{"I
tem1":"methodName","Item2":"callback"},{"Item1":"version","Item2":null},{"Item1":"parameterTypes","Item2":[{"Name":"java.lang.Class","Fields":["name"]}]},{"Item1":"parameters","Item2":[{"Item1":"name","Item2":"java.util.List"}]}]
------------------------------------------------------------
------------ 0x71----------------
ReadCompactFixList
------------ 0x72----------------
ReadCompactFixList
------------ 0x43----------------
ReadClassDefinition
------------ 0x62----------------
ReadObjectCompact
------------ 0x9b----------------
ReadIntegerSingleByte
------------ 0x4c----------------
ReadLongFull
------------ 0x43----------------
ReadClassDefinition
System.Collections.Generic.List`1[System.Object]=[[{"Name":"com.xxl.job.core.biz.model.HandleCallbackParam","Fields":["logId","logDateTim","executeResult"]},[{"Item1":"logId","Item2":11},{"Item1":"logDateTim","Item2":1547819469000},{"Item1
":"executeResult","Item2":{"Name":"com.xxl.job.core.biz.model.ReturnT","Fields":["code","msg","content"]}}]]]
------------------------------------------------------------
------------ 0x63----------------
ReadObjectCompact
------------ 0xc8----------------
ReadIntegerTwoBytes
------------ 0x03----------------
ReadShortString
------------ 0x07----------------
ReadShortString
Hessian.HessianObject=[{"Item1":"code","Item2":200},{"Item1":"msg","Item2":"1bc"},{"Item1":"content","Item2":"acd3323"}]
------------------------------------------------------------
------------ 0x62----------------
ReadObjectCompact
------------ 0xa6----------------
ReadIntegerSingleByte
------------ 0x4c----------------
ReadLongFull
------------ 0x63----------------
ReadObjectCompact
------------ 0xc9----------------
ReadIntegerTwoBytes
------------ 0x03----------------
ReadShortString
------------ 0x03----------------
ReadShortString
Hessian.HessianObject=[{"Item1":"logId","Item2":22},{"Item1":"logDateTim","Item2":1547819469000},{"Item1":"executeResult","Item2":[{"Item1":"code","Item2":500},{"Item1":"msg","Item2":"aad"},{"Item1":"content","Item2":"cac"}]}]
------------------------------------------------------------
------------------------------------------------------------

@ -12,53 +12,74 @@ namespace HessianReader
{
static void Main(string[] args)
{
byte[] myBinary = File.ReadAllBytes("request.dat");
/* */
byte[] myBinary = File.ReadAllBytes("run.dat");
foreach (var i in myBinary)
{
Console.Write("0x");
Console.Write(i.ToString("x2"));
Console.Write(",");
}
Console.WriteLine(Environment.NewLine);
Console.WriteLine("---------------------{0}------------------------------------------",myBinary.Length);
Console.WriteLine("---------------------------------------------------------------");
/*
byte[] myBinary;
var callbackParamList = new List<HandleCallbackParam> {
new HandleCallbackParam {
LogId = 11,
LogDateTime = 1547819469000L,
ExecuteResult =new ReturnT { Code = 200,Content ="acd3323",Msg ="1bc" }
},
new HandleCallbackParam {
LogId = 22,
LogDateTime = 1547819469000L,
ExecuteResult =new ReturnT { Code = 500,Content ="cac",Msg ="aad" }
}
};
var request = new RpcRequest {
RequestId ="e24123be4a76417ca6f41f227532b235",
CreateMillisTime = 1547819469003L,
AccessToken = "",
ClassName = "com.xxl.job.core.biz.AdminBiz",
MethodName = "callback",
ParameterTypes = new List<object> {new JavaClass {Name = "java.util.List"}},
Parameters = new List<object> {callbackParamList}
};
using (var stream = new MemoryStream())
{
HessianSerializer.SerializeRequest(stream,request);
myBinary = stream.ToArray();
}
*/
using (var stream1 = new MemoryStream(myBinary))
{
//var s1 = HessianSerializer.DeserializeRequest(stream1);
var s1 = HessianSerializer.DeserializeRequest(stream1);
Console.WriteLine("{0}={1}",s1.GetType(),JsonConvert.SerializeObject(s1));
/*
var s = new Deserializer(stream1);
while ( stream1.CanRead)
while ( s.CanRead())
{
var o = s.ReadValue();
Console.WriteLine("{0}={1}",o.GetType(),JsonConvert.SerializeObject(o));
Console.WriteLine("------------------------------------------------------------");
}
*/
}
Console.WriteLine("------------------------------------------------------------");
return;
RpcResponse response = new RpcResponse {
RequestId = Guid.NewGuid().ToString("N"), Result = ReturnT.Failed("ABCDEFG")
};
using (var stream2 = new MemoryStream())
{
HessianSerializer.SerializeResponse(stream2,response);
stream2.Position = 0;
var s2 =HessianSerializer.DeserializeResponse(stream2);
Console.WriteLine(JsonConvert.SerializeObject(s2));
}
Console.WriteLine("------------------------------------------------------------");
Console.ReadKey();
/**
*

Binary file not shown.

@ -55,29 +55,30 @@ namespace DotXxlJob.Core
public Task<ReturnT> Callback(List<HandleCallbackParam> callbackParamList)
{
return InvokeRpcService("callback", new List<string> {"java.util.List"}, callbackParamList);
return InvokeRpcService("callback", new List<object> {new JavaClass {Name = Constants.JavaListFulName}}, callbackParamList);
}
public Task<ReturnT> Registry(RegistryParam registryParam)
{
return InvokeRpcService("callback", new List<string> {"java.lang.Class"}, registryParam);
return InvokeRpcService("callback", new List<object> {new JavaClass {Name = Constants.JavaClassFulName}}, registryParam);
}
public Task<ReturnT> RegistryRemove(RegistryParam registryParam)
{
return InvokeRpcService("callback", new List<string> {"java.lang.Class"}, registryParam);
return InvokeRpcService("callback", new List<object> {new JavaClass {Name = Constants.JavaClassFulName}}, registryParam);
}
private async Task<ReturnT> InvokeRpcService(string methodName, List<string> parameterTypes,
private async Task<ReturnT> InvokeRpcService(string methodName, List<object> parameterTypes,
object parameters)
{
var request = new RpcRequest {
RequestId = Guid.NewGuid().ToString("N"),
CreateMillisTime = DateTime.Now.GetTotalMilliseconds(),
AccessToken = this._options.AccessToken,
ClassName = "com.xxl.job.core.biz.AdminBiz",
MethodName = methodName,
ParameterTypes = parameterTypes.ToList<object>(),
ParameterTypes = parameterTypes,
Parameters = new List<object> {parameters}
};
byte[] postBuf;
@ -90,14 +91,14 @@ namespace DotXxlJob.Core
int triedTimes = 0;
using (var client = this._clientFactory.CreateClient())
using (var client = this._clientFactory.CreateClient("DotXxlJobClient"))
{
while (triedTimes++ < this._addresses.Count)
{
var address = this._addresses[this._currentIndex];
this._currentIndex = (this._currentIndex + 1) % this._addresses.Count;
if (!address.CheckAccessable())
if (!address.CheckAccessible())
continue;
Stream resStream;

@ -6,10 +6,16 @@ namespace DotXxlJob.Core.DefaultHandlers
[JobHandler("httpJobHandler")]
public class HttpJobHandler:AbsJobHandler
{
public override Task<ReturnT> Execute(JobExecuteContext context)
public async override Task<ReturnT> Execute(JobExecuteContext context)
{
context.JobLogger.Log("Get Request Data:{0}",context.JobParameter);
return Task.FromResult(ReturnT.SUCCESS);
if (string.IsNullOrEmpty(context.JobParameter))
{
return ReturnT.Failed("url is empty");
}
//判断是否为单URL
context.JobLogger.Log("Get Request Data:{0}",context.JobParameter);
return ReturnT.SUCCESS;
}
}
}

@ -1,12 +1,49 @@
using DotXxlJob.Core.DefaultHandlers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
namespace DotXxlJob.Core
{
public class DefaultJobHandlerFactory:IJobHandlerFactory
{
private readonly IServiceProvider _provider;
private readonly Dictionary<string, IJobHandler> handlersCache = new Dictionary<string, IJobHandler>();
public DefaultJobHandlerFactory(IServiceProvider provider)
{
this._provider = provider;
Initialize();
}
private void Initialize()
{
var list = this._provider.GetServices<IJobHandler>();
if (list == null || !list.Any())
{
throw new TypeLoadException("IJobHandlers are not found in IServiceCollection");
}
foreach (var handler in list)
{
var jobHandlerAttr = handler.GetType().GetCustomAttribute<JobHandlerAttribute>();
var handlerName = jobHandlerAttr == null ? handler.GetType().Name : jobHandlerAttr.Name;
if (handlersCache.ContainsKey(handlerName))
{
throw new Exception($"same IJobHandler' name: [{handlerName}]");
}
handlersCache.Add(handlerName,handler);
}
}
public IJobHandler GetJobHandler(string handlerName)
{
return new HttpJobHandler();
if (handlersCache.ContainsKey(handlerName))
{
return handlersCache[handlerName];
}
return null;
}
}
}

@ -1,5 +1,6 @@
using System;
using DotXxlJob.Core.Config;
using DotXxlJob.Core.DefaultHandlers;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@ -23,6 +24,13 @@ namespace DotXxlJob.Core
services.Configure(configAction).AddXxlJobExecutorServiceDependency();
return services;
}
public static IServiceCollection AddDefaultXxlJobHandlers(this IServiceCollection services)
{
services.AddSingleton<IJobHandler,HttpJobHandler >();
return services;
}
private static IServiceCollection AddXxlJobExecutorServiceDependency(this IServiceCollection services)
{

@ -6,6 +6,8 @@ namespace DotXxlJob.Core
{
public const string RpcRequestJavaFullName = "com.xxl.rpc.remoting.net.params.XxlRpcRequest";
public const string RpcResponseJavaFullName = "com.xxl.rpc.remoting.net.params.XxlRpcResponse";
public const string JavaClassFulName = "java.lang.Clas";
public const string JavaListFulName = "java.util.List";
public const string XxlLogsDefaultRootDirectory = "xxl-job-logs";
public const string HandleLogsDirectory = "HandlerLogs";

@ -0,0 +1,126 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.Serialization;
using DotXxlJob.Core.Model;
using Hessian;
namespace DotXxlJob.Core
{
public class HessianObjectHelper
{
private static readonly Dictionary<string,Dictionary<string,PropertyInfo>> TransferObjCache
= new Dictionary<string, Dictionary<string, PropertyInfo>>();
private static readonly Dictionary<string,Type> TransferTypeCache
= new Dictionary<string, Type>();
static HessianObjectHelper()
{
InitProperties(typeof(RpcRequest));
InitProperties(typeof(TriggerParam));
InitProperties(typeof(RpcResponse));
InitProperties(typeof(ReturnT));
InitProperties(typeof(HandleCallbackParam));
InitProperties(typeof(JavaClass));
InitProperties(typeof(RegistryParam));
InitProperties(typeof(LogResult));
}
private static void InitProperties(Type type)
{
var propertyInfos = new Dictionary<string, PropertyInfo>();
var typeInfo = type.GetTypeInfo();
var classAttr = type.GetCustomAttribute<DataContractAttribute>();
if (classAttr == null)
{
return;
}
foreach (var property in typeInfo.DeclaredProperties)
{
var attribute = property.GetCustomAttribute<DataMemberAttribute>();
if (null == attribute)
{
continue;
}
if (!property.CanRead || !property.CanWrite)
{
continue;
}
propertyInfos.Add(attribute.Name,property);
}
TransferTypeCache.Add(classAttr.Name,type);
TransferObjCache.Add(classAttr.Name,propertyInfos);
}
public static object GetRealObjectValue(object value)
{
if (value == null || IsSimpleType(value.GetType()))
{
return value;
}
if (value is HessianObject hessianObject)
{
if(TransferObjCache.TryGetValue(hessianObject.TypeName,out var properties))
{
var instance = Activator.CreateInstance(TransferTypeCache[hessianObject.TypeName]);
foreach (var (k, v) in hessianObject)
{
if (properties.TryGetValue(k, out var p))
{
p.SetValue(instance,GetRealObjectValue(v));
}
}
return instance;
}
}
if (IsListType(value.GetType()))
{
var listData = new List<object>();
var cList = value as List<object>;
foreach (var cItem in cList)
{
listData.Add(GetRealObjectValue(cItem));
}
return listData;
}
throw new HessianException($"unknown item:{value.GetType()}");
}
private static bool IsListType(Type type)
{
return typeof(ICollection).IsAssignableFrom(type);
}
private static bool IsSimpleType(Type typeInfo)
{
if (typeInfo.IsValueType || typeInfo.IsEnum || typeInfo.IsPrimitive)
{
return true;
}
if (typeof (string) == typeInfo)
{
return true;
}
return false;
}
}
}

@ -1,10 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net.NetworkInformation;
using System.Reflection;
using System.Runtime.Serialization;
using DotXxlJob.Core.Model;
using Hessian;
@ -12,61 +6,10 @@ namespace DotXxlJob.Core
{
public static class HessianSerializer
{
private static readonly Dictionary<string, PropertyInfo> requestProperties =
new Dictionary<string, PropertyInfo>();
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>();
private static readonly Dictionary<string, PropertyInfo> callbackProperties =
new Dictionary<string, PropertyInfo>();
static HessianSerializer()
{
InitProperties(typeof(RpcRequest), requestProperties);
InitProperties(typeof(TriggerParam), triggerProperties);
InitProperties(typeof(RpcResponse), responseProperties);
InitProperties(typeof(ReturnT), returnProperties);
InitProperties(typeof(HandleCallbackParam), callbackProperties);
}
private static void InitProperties(Type type, Dictionary<string, PropertyInfo> propertyInfos)
{
var typeInfo = type.GetTypeInfo();
foreach (var property in typeInfo.DeclaredProperties)
{
var attribute = property.GetCustomAttribute<DataMemberAttribute>();
if (null == attribute)
{
continue;
}
if (!property.CanRead || !property.CanWrite)
{
continue;
}
propertyInfos.Add(attribute.Name,property);
}
}
public static RpcRequest DeserializeRequest(Stream stream)
{
RpcRequest request = new RpcRequest();
RpcRequest request = null;
try
{
@ -76,123 +19,17 @@ namespace DotXxlJob.Core
{
throw new HessianException($"unknown class :{classDef.Name}");
}
if (requestProperties.Count != classDef.Fields.Length)
{
throw new HessianException($"unknown class :{classDef.Name}, field count not match ${requestProperties.Count} !={classDef.Fields.Length}");
}
//obj serialize
if (deserializer.ReadValue() is HessianObject hessianObject)
{
foreach (var item in hessianObject)
{
if (requestProperties.TryGetValue(item.Item1, out var p))
{
if (IsSimpleType(p.PropertyType.GetTypeInfo()))
{
p.SetValue(request,item.Item2);
}
else
{
if (item.Item1 == "parameterTypes")
{
request.ParameterTypes = item.Item2 as List<object>;
}
else if (item.Item2 is HessianObject )
{
request.Parameters = new List<object>();
var defList = deserializer.ReadValue() as List<object>;
foreach (var li in defList)
{
ReadParameters(deserializer,request.Parameters, li);
}
}
else
{
throw new HessianException($"unknown item :{item.Item1},{item.Item2.GetType()}");
}
}
}
}
}
request = HessianObjectHelper.GetRealObjectValue(deserializer.ReadValue()) as RpcRequest;
}
catch (EndOfStreamException)
{
//没有数据可读了
}
return request;
}
private static void ReadParameters(Deserializer deserializer,IList<object> list, object item)
{
var itemType = item.GetType();
if (IsSimpleType(itemType.GetTypeInfo()))
{
list.Add(item);
return;
}
if (item is ClassDef paramClass)
{
//TODO:这里要做成动态的话 ,可以注册所有的实体到对应的字典中,不过这里只有这个类型哦
if (paramClass.Name != "com.xxl.job.core.biz.model.TriggerParam")
{
throw new HessianException($"not expected parameter type [{paramClass.Name}]");
}
if (!(deserializer.ReadValue() is HessianObject paramData))
{
throw new HessianException("not expected parameter type ,data is null");
}
object val ;
if (paramClass.Name == "com.xxl.job.core.biz.model.TriggerParam")
{
val =new TriggerParam();
}
else
{
val =new HandleCallbackParam();
}
foreach (var (key,value) in paramData)
{
if (triggerProperties.TryGetValue(key, out var tgPropertyInfo))
{
tgPropertyInfo.SetValue(val,value);
}
}
list.Add(val);
}
else if (item is HessianObject hessianObject)
{
if (hessianObject.TypeName == "com.xxl.job.core.biz.model.HandleCallbackParam")
{
var val =new HandleCallbackParam();
foreach (var (key,value) in hessianObject)
{
if (triggerProperties.TryGetValue(key, out var tgPropertyInfo))
{
tgPropertyInfo.SetValue(val,value);
}
}
list.Add(val);
}
}
else
{
throw new HessianException($"unsupported list item type =[{itemType}]");
}
}
public static void SerializeRequest(Stream stream,RpcRequest req)
{
var serializer = new Serializer(stream);
@ -205,24 +42,10 @@ namespace DotXxlJob.Core
serializer.WriteObject(res);
}
private static bool IsSimpleType(TypeInfo typeInfo)
{
if (typeInfo.IsValueType || typeInfo.IsEnum || typeInfo.IsPrimitive)
{
return true;
}
if (typeof (string) == typeInfo.AsType())
{
return true;
}
return false;
}
public static RpcResponse DeserializeResponse(Stream resStream)
{
var rsp = new RpcResponse();
RpcResponse rsp = null;
try
{
@ -232,58 +55,7 @@ namespace DotXxlJob.Core
{
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");
}
var data = new ReturnT();
foreach (var (key, value) in resultData)
{
if (returnProperties.TryGetValue(key, out var tgPropertyInfo))
{
tgPropertyInfo.SetValue(data,value);
}
}
rsp.Result = data;
}
else
{
throw new HessianException($"unknown item :{item.Item1},{item.Item2.GetType()}");
}
}
}
}
}
rsp = HessianObjectHelper.GetRealObjectValue(deserializer.ReadValue()) as RpcResponse;
}
catch (EndOfStreamException)
@ -293,6 +65,8 @@ namespace DotXxlJob.Core
return rsp;
}
}

@ -10,7 +10,7 @@ namespace DotXxlJob.Core.Model
private int FailedTimes { get; set; }
public bool CheckAccessable()
public bool CheckAccessible()
{
if (LastFailedTime == null)
return true;

@ -2,7 +2,7 @@ using System.Runtime.Serialization;
namespace DotXxlJob.Core.Model
{
[DataContract(Name = "")]
[DataContract(Name = "com.xxl.job.core.biz.model.RegistryParam")]
public class RegistryParam
{
[DataMember(Name = "registGroup",Order = 1)]

@ -8,7 +8,7 @@ namespace DotXxlJob.Core.Model
[DataMember(Name = "requestId",Order = 1)]
public string RequestId{ get; set; }
[DataMember(Name = "errorMsg",Order = 2)]
public string ErrorMsg;
public string ErrorMsg { get; set; }
[DataMember(Name = "result",Order = 3)]
public object Result{ get; set; }

@ -1,70 +0,0 @@
using System;
using System.IO;
namespace Hessian.Net
{
/// <summary>
/// Serialize objects to binary and deserialize binary to objects using the Caucho Hessian 2.0 Serialization Protocol.
/// </summary>
/// <remarks>
/// This class cannot be inherited.
/// </remarks>
public sealed class DataContractHessianSerializer
{
private readonly Type type;
/// <summary>
/// Initializes a new instance of the <see cref="DataContractHessianSerializer" /> class to serialize or deserialize an object of the specified type and serializer settings.
/// </summary>
/// <param name="type">The type of the instance that is serialized or deserialized.</param>
/// <param name="settings">The serializer settings.</param>
public DataContractHessianSerializer(Type type, HessianSerializerSettings settings = null)
{
this.type = type;
}
/// <summary>
/// Serializes a specified object to binary data and writes the resulting to a stream.
/// </summary>
/// <param name="stream">The <see cref="System.IO.Stream" /> that is written to.</param>
/// <param name="graph">The object that contains the data to write to the stream.</param>
public void WriteObject(Stream stream, object graph)
{
if (null == stream)
{
throw new ArgumentNullException(nameof(stream));
}
var factory = new HessianObjectSerializerFactory();
var scheme = HessianSerializationScheme.CreateFromType(type, factory);
using (var writer = new HessianOutputWriter(stream))
{
var context = new HessianSerializationContext();
scheme.Serialize(writer, graph, context);
}
}
/// <summary>
///
/// </summary>
/// <param name="stream"></param>
/// <returns></returns>
public object ReadObject(Stream stream)
{
if (null == stream)
{
throw new ArgumentNullException(nameof(stream));
}
var factory = new HessianObjectSerializerFactory();
var scheme = HessianSerializationScheme.CreateFromType(type, factory);
using (var reader = new HessianInputReader(stream))
{
var context = new HessianSerializationContext();
return scheme.Deserialize(reader, context);
}
}
}
}

@ -1,54 +0,0 @@
using System;
using System.IO;
namespace Hessian.Net
{
/// <summary>
///
/// </summary>
public class DisposableStreamHandler : IDisposable
{
private bool disposed;
protected Stream Stream
{
get;
private set;
}
protected DisposableStreamHandler(Stream stream)
{
Stream = stream;
}
/// <summary>
///
/// </summary>
public void Dispose()
{
if (!disposed)
{
Dispose(true);
}
}
protected virtual void Dispose(bool dispose)
{
if (!disposed)
{
try
{
if (dispose)
{
Stream.Dispose();
Stream = null;
}
}
finally
{
disposed = true;
}
}
}
}
}

@ -1,56 +0,0 @@
using System;
namespace Hessian.Net.Extension
{
/// <summary>
///
/// </summary>
internal static class DateTimeExtension
{
private const long Era = 62135596800000L;
private const long Millis = 60000;
/// <summary>
///
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public static long GetTotalMilliseconds(this DateTime dt)
{
return dt.ToUniversalTime().Ticks / 10000 - Era;
}
/// <summary>
///
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public static int GetTotalMinutes(this DateTime dt)
{
var val = GetTotalMilliseconds(dt);
return (int)(val / Millis);
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static DateTime FromMinutes(int value)
{
var ticks = (value * Millis + Era) * 10000;
return new DateTime(ticks, DateTimeKind.Utc);
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static DateTime FromMilliseconds(long value)
{
var ticks = (value + Era) * 10000;
return new DateTime(ticks, DateTimeKind.Utc);
}
}
}

@ -1,75 +0,0 @@
using System;
namespace Hessian.Net.Extension
{
/// <summary>
///
/// </summary>
internal static class Maybe
{
/// <summary>
///
/// </summary>
/// <typeparam name="TInput"></typeparam>
/// <typeparam name="TResult"></typeparam>
/// <param name="value"></param>
/// <param name="eval"></param>
/// <returns></returns>
public static TResult With<TInput, TResult>(this TInput value, Func<TInput, TResult> eval)
where TResult : class
{
return (null == value) ? null : eval(value);
}
/// <summary>
///
/// </summary>
/// <typeparam name="TInput"></typeparam>
/// <typeparam name="TResult"></typeparam>
/// <param name="value"></param>
/// <param name="eval"></param>
/// <param name="failure"></param>
/// <returns></returns>
public static TResult Return<TInput, TResult>(this TInput value, Func<TInput, TResult> eval, TResult failure)
where TResult : class
{
return (null == value) ? failure : eval(value);
}
/// <summary>
///
/// </summary>
/// <typeparam name="TInput"></typeparam>
/// <param name="value"></param>
/// <param name="condition"></param>
/// <returns></returns>
public static TInput If<TInput>(this TInput value, Predicate<TInput> condition)
where TInput : class
{
if (null == value)
{
return null;
}
return condition(value) ? value : null;
}
/// <summary>
///
/// </summary>
/// <typeparam name="TInput"></typeparam>
/// <param name="value"></param>
/// <param name="condition"></param>
/// <returns></returns>
public static TInput Unless<TInput>(this TInput value, Predicate<TInput> condition)
where TInput : class
{
if (null == value)
{
return null;
}
return condition(value) ? null : value;
}
}
}

@ -1,7 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>

@ -1,664 +0,0 @@
using System;
using System.IO;
using System.Text;
using Hessian.Net.Extension;
namespace Hessian.Net
{
public class HessianInputReader : DisposableStreamHandler
{
private ObjectPreamble preamble;
public bool IsClassDefinition => ObjectPreamble.ClassDefinition == preamble;
public bool IsInstanceReference => ObjectPreamble.InstanceReference == preamble;
public LeadingByte LeadingByte
{
get;
}
public HessianInputReader(Stream stream)
: base(stream)
{
LeadingByte = new LeadingByte();
}
/// <summary>
/// Reads <see cref="System.Boolean" /> value from the stream.
/// </summary>
/// <returns>The value</returns>
public virtual bool ReadBoolean()
{
ReadLeadingByte();
if (LeadingByte.IsTrue)
{
return true;
}
if (!LeadingByte.IsFalse)
{
throw new HessianSerializerException();
}
return false;
}
public virtual int ReadInt32()
{
ReadLeadingByte();
if (LeadingByte.IsTinyInt32)
{
return LeadingByte.Data - 144;
}
if (LeadingByte.IsShortInt32)
{
return ReadShortInt32();
}
if (LeadingByte.IsCompactInt32)
{
return ReadCompactInt32();
}
if (!LeadingByte.IsUnpackedInt32)
{
throw new HessianSerializerException();
}
return ReadUnpackedInt32();
}
public virtual long ReadInt64()
{
ReadLeadingByte();
if (LeadingByte.IsTinyInt64)
{
return LeadingByte.Data - 224;
}
if (LeadingByte.IsShortInt64)
{
return ReadShortInt64();
}
if (LeadingByte.IsCompactInt64)
{
return ReadCompactInt64();
}
if (LeadingByte.IsPackedInt64)
{
return ReadPackedInt64();
}
if (!LeadingByte.IsUnpackedInt64)
{
throw new HessianSerializerException();
}
return ReadUnpackedInt64();
}
/// <summary>
/// Reads binary data from stream.
/// </summary>
/// <returns>The array of bytes.</returns>
public virtual byte[] ReadBytes()
{
ReadLeadingByte();
if (LeadingByte.IsNull)
{
return null;
}
if (LeadingByte.IsCompactBinary)
{
return ReadBinaryCompact15();
}
var count = 0;
var buffer = new byte[0];
while (LeadingByte.IsNonfinalChunkBinary || LeadingByte.IsFinalChunkBinary)
{
var length = GetChunkLength();
if (buffer.Length < (count + length))
{
var temp = new byte[count + length];
Buffer.BlockCopy(buffer, 0, temp, 0, buffer.Length);
buffer = temp;
}
if (Stream.Read(buffer, count, length) != length)
{
throw new HessianSerializerException();
}
count += length;
if (LeadingByte.IsFinalChunkBinary)
{
break;
}
ReadLeadingByte();
}
return buffer;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public virtual double ReadDouble()
{
ReadLeadingByte();
if (LeadingByte.IsZeroDouble)
{
return 0.0d;
}
if (LeadingByte.IsOneDouble)
{
return 1.0d;
}
if (LeadingByte.IsTinyDouble)
{
return Stream.ReadByte();
}
if (LeadingByte.IsShortDouble)
{
return ReadShortDouble();
}
if (LeadingByte.IsCompactDouble)
{
return ReadCompactDouble();
}
if (!LeadingByte.IsUnpackedDouble)
{
throw new HessianSerializerException();
}
return ReadUnpackedDouble();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public virtual string ReadString()
{
ReadLeadingByte();
if (LeadingByte.IsTinyString)
{
return GetStringChunk(LeadingByte.Data);
}
if (LeadingByte.IsCompactString)
{
return ReadCompactString();
}
var builder = new StringBuilder();
while (LeadingByte.IsNonfinalChunkString || LeadingByte.IsFinalChunkString)
{
var chunkLength = GetChunkLength();
var chunk = GetStringChunk(chunkLength);
builder.Append(chunk);
if (LeadingByte.IsFinalChunkString)
{
break;
}
ReadLeadingByte();
}
return builder.ToString();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public virtual DateTime ReadDateTime()
{
ReadLeadingByte();
if (LeadingByte.IsCompactDateTime)
{
var minutes = ReadUnpackedInt32();
return DateTimeExtension.FromMinutes(minutes);
}
if (!LeadingByte.IsUnpackedDateTime)
{
throw new HessianSerializerException();
}
return DateTimeExtension.FromMilliseconds(ReadUnpackedInt64());
}
/// <summary>
///
/// </summary>
public void BeginObject()
{
ReadLeadingByte();
if (LeadingByte.IsClassDefinition)
{
preamble = ObjectPreamble.ClassDefinition;
}
else if (LeadingByte.IsShortObjectReference || LeadingByte.IsLongObjectReference)
{
preamble = ObjectPreamble.ObjectReference;
}
else if (LeadingByte.IsInstanceReference)
{
preamble = ObjectPreamble.InstanceReference;
}
else
{
throw new HessianSerializerException();
}
}
public void EndObject()
{
preamble = ObjectPreamble.None;
}
public ObjectPreamble BeginList()
{
ReadLeadingByte();
if (LeadingByte.IsVarList)
{
preamble = ObjectPreamble.VarList;
}
else if (LeadingByte.IsFixedList)
{
preamble = ObjectPreamble.FixList;
}
else if (LeadingByte.IsVarListUntyped)
{
preamble = ObjectPreamble.VarListUntyped;
}
else if (LeadingByte.IsFixListUntyped)
{
preamble = ObjectPreamble.FixListUntyped;
}
else if (LeadingByte.IsCompactFixList)
{
preamble = ObjectPreamble.CompactFixList;
}
else if (LeadingByte.IsCompactFixListUntyped)
{
preamble = ObjectPreamble.CompactFixListUntyped;
}
else
{
throw new HessianSerializerException();
}
return preamble;
}
public void EndList()
{
preamble = ObjectPreamble.None;
}
public void EndClassDefinition()
{
}
public int ReadObjectReference()
{
ReadLeadingByte();
if (LeadingByte.IsShortObjectReference)
{
return LeadingByte.Data - 0x60;
}
if (!LeadingByte.IsLongObjectReference)
{
throw new HessianSerializerException();
}
return ReadInt32();
}
public int ReadInstanceReference()
{
return ReadInt32();
}
public byte Peek()
{
byte value= (byte)this.Stream.ReadByte();
this.Stream.Position--;
return value;
}
public byte ReadByte()
{
return (byte)this.Stream.ReadByte();
}
protected void ReadLeadingByte()
{
var data = Stream.ReadByte();
Console.WriteLine(data.ToString("x2"));
if (-1 == data)
{
throw new HessianSerializerException();
}
LeadingByte.SetData((byte)data);
}
private int ReadShortInt32()
{
var data = Stream.ReadByte();
return ((LeadingByte.Data - 200) << 8) | data;
}
private int ReadCompactInt32()
{
var value = (LeadingByte.Data - 212) << 16;
value |= (Stream.ReadByte() << 8);
value |= Stream.ReadByte();
return value;
}
private int ReadUnpackedInt32()
{
var value = Stream.ReadByte() << 24;
value |= (Stream.ReadByte() << 16);
value |= (Stream.ReadByte() << 8);
value |= Stream.ReadByte();
return value;
}
private long ReadShortInt64()
{
var data = Stream.ReadByte();
return ((LeadingByte.Data - 248) << 8) | data;
}
private long ReadCompactInt64()
{
var value = (LeadingByte.Data - 60) << 16;
value |= (Stream.ReadByte() << 8);
value |= Stream.ReadByte();
return value;
}
private long ReadPackedInt64()
{
var value = Stream.ReadByte() << 24;
value |= (Stream.ReadByte() << 16);
value |= (Stream.ReadByte() << 8);
value |= Stream.ReadByte();
return value;
}
private long ReadUnpackedInt64()
{
var value = (long) Stream.ReadByte() << 56;
value |= ((long) Stream.ReadByte() << 48);
value |= ((long) Stream.ReadByte() << 40);
value |= ((long) Stream.ReadByte() << 32);
value |= ((long) Stream.ReadByte() << 24);
value |= ((long) Stream.ReadByte() << 16);
value |= ((long) Stream.ReadByte() << 8);
value |= (uint)Stream.ReadByte();
return value;
}
private byte[] ReadBinaryCompact15()
{
var size = LeadingByte.Data - 32;
var temp = new byte[size];
if (Stream.Read(temp, 0, size) != size)
{
throw new HessianSerializerException();
}
return temp;
}
private double ReadShortDouble()
{
var value = Stream.ReadByte() << 8;
value |= Stream.ReadByte();
return Convert.ToDouble((short)value);
}
private double ReadCompactDouble()
{
var buffer = new byte[4];
for (var index = buffer.Length - 1; index >= 0; index--)
{
buffer[index] = (byte)Stream.ReadByte();
}
return BitConverter.ToSingle(buffer, 0);
}
private double ReadUnpackedDouble()
{
var value = 0L;
for (var count = 8; count > 0; count--)
{
value <<= 8;
value |= (uint)Stream.ReadByte();
}
return BitConverter.Int64BitsToDouble(value);
}
private string ReadCompactString()
{
var length = (LeadingByte.Data - 0x30) << 8;
length |= Stream.ReadByte();
return GetStringChunk(length);
}
private string GetStringChunk(int length)
{
var buffer = new StringBuilder();
while (length-- > 0)
{
var ch = ReadChar();
buffer.Append(ch);
}
return buffer.ToString();
}
private int GetChunkLength()
{
var b0 = Stream.ReadByte();
var b1 = Stream.ReadByte();
return (b0 << 8) + b1;
}
private char ReadChar()
{
var data = Stream.ReadByte();
if (data < 0x80)
{
return (char)data;
}
if ((data & 0xE0) == 0xC0)
{
var b0 = Stream.ReadByte();
return (char) (((data & 0x1F) << 6) + (b0 & 0x3F));
}
if ((data & 0xF0) == 0xE0)
{
var b0 = Stream.ReadByte();
var b1 = Stream.ReadByte();
return (char) (((data & 0x0F) << 12) + ((b0 & 0x3F) << 6) + (b1 & 0x3F));
}
throw new HessianSerializerException();
}
/*
* hessian implementation
* https://github.com/benjamin-bader/hessian/blob/master/Hessian/ValueReader.cs
public uint ReadUtf8Codepoint ()
{
const uint replacementChar = 0xFFFD;
byte b0, b1, b2, b3;
b0 = ReadByte ();
if (b0 < 0x80) {
return b0;
}
if (b0 < 0xC2) {
return replacementChar;
}
if (b0 < 0xE0) {
b1 = ReadByte ();
if ((b1 ^ 0x80) >= 0x40) {
return replacementChar;
}
return (b1 & 0x3Fu) | ((b0 & 0x1Fu) << 6);
}
if (b0 < 0xF0) {
b1 = ReadByte ();
b2 = ReadByte ();
// Valid range: E0 A0..BF 80..BF
if (b0 == 0xE0 && (b1 ^ 0xA0) >= 0x20) {
return replacementChar;
}
// Valid range: ED 80..9F 80..BF
if (b0 == 0xED && (b1 ^ 0x80) >= 0x20) {
return replacementChar;
}
// Valid range: E1..EC 80..BF 80..BF
if ((b1 ^ 0x80) >= 0x40 || (b2 ^ 0x80) >= 0x40) {
return replacementChar;
}
return (b2 & 0x3Fu)
| ((b1 & 0x3Fu) << 6)
| ((b0 & 0x0Fu) << 12);
}
if (b0 < 0xF1) {
b1 = ReadByte();
if ((b1 ^ 0x90) < 0x30) {
return replacementChar;
}
b2 = ReadByte();
b3 = ReadByte();
if ((b2 & 0xC0) != 0x80 || (b3 & 0xC0) != 0x80) {
return replacementChar;
}
return (b3 & 0x3Fu)
| ((b2 & 0x3Fu) << 6)
| ((b1 & 0x3Fu) << 12)
| ((b0 & 0x07u) << 18);
}
if (b0 < 0xF4) {
b1 = ReadByte ();
b2 = ReadByte ();
b3 = ReadByte ();
// Valid range: F1..F3 80..BF 80..BF 80..BF
if ((b1 & 0xC0) != 0x80 || (b2 & 0xC0) != 0x80 || (b3 & 0xC0) != 0x80)
{
return replacementChar;
}
return (b3 & 0x3Fu)
| ((b2 & 0x3Fu) << 6)
| ((b1 & 0x3Fu) << 12)
| ((b0 & 0x07u) << 18);
}
if (b0 < 0xF5) {
b1 = ReadByte ();
// Valid range: F4 80..8F 80..BF 80..BF
if ((b1 ^ 0x80) >= 0x10) {
return replacementChar;
}
b2 = ReadByte();
b3 = ReadByte();
if ((b2 & 0xC0) != 0x80 || (b3 & 0xC0) != 0x80)
{
return replacementChar;
}
return (b3 & 0x3Fu)
| ((b2 & 0x3Fu) << 6)
| ((b1 & 0x3Fu) << 12)
| ((b0 & 0x07u) << 18);
}
return replacementChar;
}*/
}
}

@ -1,45 +0,0 @@
using System;
using System.Collections.Generic;
namespace Hessian.Net
{
internal sealed partial class HessianObjectSerializerFactory : IObjectSerializerFactory
{
//private readonly HessianSerializationContext context;
private Dictionary<Type, IObjectSerializer> cache;
//public HessianObjectSerializerFactory(HessianSerializationContext context)
//{
// this.context = context;
//}
public IObjectSerializer GetSerializer(Type target)
{
IObjectSerializer writer;
EnsureCache();
return cache.TryGetValue(target, out writer) ? writer : null;
}
private void EnsureCache()
{
if (null != cache)
{
return;
}
var dict = new Dictionary<Type, IObjectSerializer>
{
[typeof (bool)] = new BooleanSerializer(),
[typeof (int)] = new Int32Serializer(),
[typeof (long)] = new Int64Serializer(),
[typeof (double)] = new DoubleSerializer(),
[typeof (string)] = new StringSerializer(),
[typeof (DateTime)] = new DateTimeSerializer()
};
cache = dict;
}
}
}

@ -1,128 +0,0 @@
using System;
namespace Hessian.Net
{
internal partial class HessianObjectSerializerFactory
{
/// <summary>
///
/// </summary>
private class BooleanSerializer : IObjectSerializer
{
public void Serialize(HessianOutputWriter writer, object graph)
{
writer.WriteBoolean((bool) graph);
}
public object Deserialize(HessianInputReader reader)
{
return reader.ReadBoolean();
}
}
/// <summary>
///
/// </summary>
private class Int32Serializer : IObjectSerializer
{
public void Serialize(HessianOutputWriter writer, object graph)
{
writer.WriteInt32((int) graph);
}
public object Deserialize(HessianInputReader reader)
{
return reader.ReadInt32();
}
}
/// <summary>
///
/// </summary>
private class Int64Serializer : IObjectSerializer
{
public void Serialize(HessianOutputWriter writer, object graph)
{
writer.WriteInt64((long) graph);
}
public object Deserialize(HessianInputReader reader)
{
return reader.ReadInt64();
}
}
/// <summary>
///
/// </summary>
private class StringSerializer : IObjectSerializer
{
public void Serialize(HessianOutputWriter writer, object graph)
{
writer.WriteString((string) graph);
}
public object Deserialize(HessianInputReader reader)
{
return reader.ReadString();
}
}
/// <summary>
///
/// </summary>
private class DateTimeSerializer : IObjectSerializer
{
public void Serialize(HessianOutputWriter writer, object graph)
{
writer.WriteDateTime((DateTime) graph);
}
public object Deserialize(HessianInputReader reader)
{
return reader.ReadDateTime();
}
}
/// <summary>
///
/// </summary>
private class DoubleSerializer : IObjectSerializer
{
public void Serialize(HessianOutputWriter writer, object graph)
{
writer.WriteDouble((double) graph);
}
public object Deserialize(HessianInputReader reader)
{
return reader.ReadDouble();
}
}
/*
/// <summary>
///
/// </summary>
private class ClassSerializer : IObjectSerializer
{
private readonly HessianSerializationContext context;
public ClassSerializer(HessianSerializationContext context)
{
this.context = context;
}
public void Serialize(HessianOutputWriter writer, object graph)
{
throw new System.NotImplementedException();
}
public object Deserialize(HessianInputReader reader)
{
return reader.
}
}
*/
}
}

@ -1,321 +0,0 @@
using System;
using System.IO;
using System.Text;
using Hessian.Net.Extension;
namespace Hessian.Net
{
/// <summary>
/// Class for writing Hessian-encoded data into stream.
/// </summary>
public class HessianOutputWriter : DisposableStreamHandler
{
public HessianOutputWriter(Stream stream)
: base(stream)
{
}
/// <summary>
/// Writes NULL token into stream
/// </summary>
public virtual void WriteNull()
{
Stream.WriteByte(Marker.Null);
}
/// <summary>
/// Writes <see cref="System.Boolean" /> value into output stream.
/// </summary>
/// <param name="value">The value.</param>
public virtual void WriteBoolean(bool value)
{
Stream.WriteByte(value ? Marker.True : Marker.False);
}
/// <summary>
/// Writes array of <see cref="System.Byte" /> into output stream.
/// </summary>
/// <param name="buffer">The value.</param>
public void WriteBytes(byte[] buffer)
{
if (null == buffer)
{
WriteNull();
return;
}
WriteBytes(buffer, 0, buffer.Length);
}
public virtual void WriteBytes(byte[] buffer, int offset, int count)
{
if (offset < 0)
{
throw new ArgumentException("", nameof(offset));
}
if (null == buffer)
{
WriteNull();
return;
}
if (count < 0x10)
{
Stream.WriteByte((byte)(0x20 + (count & 0x0F)));
Stream.Write(buffer, offset, count);
return;
}
const int chunkSize = 0x8000;
while (count > chunkSize)
{
Stream.WriteByte(Marker.BinaryNonfinalChunk);
Stream.WriteByte(chunkSize >> 8);
Stream.WriteByte(chunkSize & 0xFF);
Stream.Write(buffer, offset, chunkSize);
count -= chunkSize;
offset += chunkSize;
}
Stream.WriteByte(Marker.BinaryFinalChunk);
Stream.WriteByte((byte)(count >> 8));
Stream.WriteByte((byte)(count & 0xFF));
Stream.Write(buffer, offset, count);
}
public virtual void WriteDateTime(DateTime value)
{
if (value.Second == 0)
{
var s = value.GetTotalMinutes();
Stream.WriteByte(Marker.DateTimeCompact);
Stream.WriteByte((byte)(s >> 24));
Stream.WriteByte((byte)(s >> 16));
Stream.WriteByte((byte)(s >> 8));
Stream.WriteByte((byte)s);
return;
}
var dt = value.GetTotalMilliseconds();
Stream.WriteByte(Marker.DateTimeLong);
Stream.WriteByte((byte)(dt >> 56));
Stream.WriteByte((byte)(dt >> 48));
Stream.WriteByte((byte)(dt >> 40));
Stream.WriteByte((byte)(dt >> 32));
Stream.WriteByte((byte)(dt >> 24));
Stream.WriteByte((byte)(dt >> 16));
Stream.WriteByte((byte)(dt >> 8));
Stream.WriteByte((byte)dt);
}
public virtual void WriteDouble(double value)
{
if (value.Equals(0.0d))
{
Stream.WriteByte(Marker.DoubleZero);
return;
}
if (value.Equals(1.0d))
{
Stream.WriteByte(Marker.DoubleOne);
return;
}
var fraction = Math.Abs(value - Math.Truncate(value));
if (Double.Epsilon >= fraction)
{
if (Byte.MinValue <= value && value <= Byte.MaxValue)
{
Stream.WriteByte(Marker.DoubleOctet);
Stream.WriteByte(Convert.ToByte(value));
return;
}
if (Int16.MinValue <= value && value <= Int16.MaxValue)
{
var val = Convert.ToInt16(value);
Stream.WriteByte(Marker.DoubleShort);
Stream.WriteByte((byte)(val >> 8));
Stream.WriteByte((byte)val);
return;
}
}
if (Single.MinValue <= value && value <= Single.MaxValue)
{
var bytes = BitConverter.GetBytes((float) value);
Stream.WriteByte(Marker.DoubleFloat);
for (var index = bytes.Length - 1; index >= 0; index--)
{
Stream.WriteByte(bytes[index]);
}
return;
}
var temp = BitConverter.DoubleToInt64Bits(value);
Stream.WriteByte(Marker.Double);
for (var index = 56; index >= 0; index -= 8)
{
Stream.WriteByte((byte) (temp >> index));
}
}
public virtual void WriteInt32(int value)
{
if (-16 <= value && value < 48)
{
Stream.WriteByte((byte)(0x90 + value));
}
else if (-2048 <= value && value < 2048)
{
Stream.WriteByte((byte)(0xC8 + (byte)(value >> 8)));
Stream.WriteByte((byte)value);
}
else if (-262144 <= value && value < 262144)
{
Stream.WriteByte((byte)(0xD4 + (byte)(value >> 16)));
Stream.WriteByte((byte)(value >> 8));
Stream.WriteByte((byte)value);
}
else
{
Stream.WriteByte(Marker.UnpackedInteger);
Stream.WriteByte((byte)(value >> 24));
Stream.WriteByte((byte)(value >> 16));
Stream.WriteByte((byte)(value >> 8));
Stream.WriteByte((byte)value);
}
}
public virtual void WriteInt64(long value)
{
if (-8 <= value && value < 16)
{
Stream.WriteByte((byte)(0xE0 + value));
}
else if (-2048 <= value && value < 2048)
{
Stream.WriteByte((byte)(0xF8 + (byte)(value >> 8)));
Stream.WriteByte((byte)value);
}
else if (-262144 <= value && value < 262144)
{
Stream.WriteByte((byte)(0x3C + (byte)(value >> 16)));
Stream.WriteByte((byte)(value >> 8));
Stream.WriteByte((byte)value);
}
else if (Int32.MinValue <= value && value <= Int32.MaxValue)
{
Stream.WriteByte(Marker.PackedLong);
Stream.WriteByte((byte)(value >> 24));
Stream.WriteByte((byte)(value >> 16));
Stream.WriteByte((byte)(value >> 8));
Stream.WriteByte((byte)value);
}
else
{
Stream.WriteByte(Marker.UnpackedLong);
Stream.WriteByte((byte)(value >> 56));
Stream.WriteByte((byte)(value >> 48));
Stream.WriteByte((byte)(value >> 40));
Stream.WriteByte((byte)(value >> 32));
Stream.WriteByte((byte)(value >> 24));
Stream.WriteByte((byte)(value >> 16));
Stream.WriteByte((byte)(value >> 8));
Stream.WriteByte((byte)value);
}
}
public virtual void WriteString(string value)
{
if (String.IsNullOrEmpty(value))
{
Stream.WriteByte(0x00);
return;
}
var length = value.Length;
if (1024 > length)
{
var bytes = Encoding.UTF8.GetBytes(value.ToCharArray());
if (32 > length)
{
Stream.WriteByte((byte) length);
}
else
{
Stream.WriteByte((byte) (0x30 + (byte) (length >> 8)));
Stream.WriteByte((byte) length);
}
Stream.Write(bytes, 0, bytes.Length);
return;
}
const int maxChunkLength = 1024;
var position = 0;
while (position < length)
{
var count = Math.Min(length - position, maxChunkLength);
var final = length == (position + count);
var chunk = value.Substring(position, count);
var bytes = Encoding.UTF8.GetBytes(chunk.ToCharArray());
Stream.WriteByte(final ? Marker.StringFinalChunk : Marker.StringNonfinalChunk);
Stream.WriteByte((byte)(count >> 8));
Stream.WriteByte((byte)count);
Stream.Write(bytes, 0, bytes.Length);
position += count;
}
}
public virtual void BeginClassDefinition()
{
Stream.WriteByte(Marker.ClassDefinition);
}
public virtual void EndClassDefinition()
{
}
public virtual void WriteObjectReference(int index)
{
if (index < 0x10)
{
Stream.WriteByte((byte)(0x60 + index));
}
else
{
Stream.WriteByte(Marker.ClassReference);
WriteInt32(index);
}
}
public virtual void WriteInstanceReference(int index)
{
Stream.WriteByte(Marker.InstanceReference);
WriteInt32(index);
}
}
}

@ -1,27 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Hessian.Net
{
public class HessianSerializationContext
{
public IList<Type> Classes
{
get;
private set;
}
public IList Instances
{
get;
private set;
}
public HessianSerializationContext()
{
Classes = new List<Type>();
Instances = new List<object>();
}
}
}

@ -1,127 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.Serialization;
namespace Hessian.Net
{
internal class HessianSerializationScheme
{
public Type ObjectType
{
get;
private set;
}
public ISerializationElement Element
{
get;
}
private HessianSerializationScheme(Type objectType, ISerializationElement element)
{
ObjectType = objectType;
Element = element;
}
public static HessianSerializationScheme CreateFromType(Type type, IObjectSerializerFactory factory)
{
var catalog = new Dictionary<Type, ISerializationElement>();
var element = CreateSerializationElement(type, catalog, factory);
return new HessianSerializationScheme(type, element);
}
public void Serialize(HessianOutputWriter writer, object graph, HessianSerializationContext context)
{
Element.Serialize(writer, graph, context);
}
public object Deserialize(HessianInputReader reader, HessianSerializationContext context)
{
return Element.Deserialize(reader, context);
}
private static ISerializationElement CreateSerializationElement(Type type, IDictionary<Type, ISerializationElement> catalog, IObjectSerializerFactory factory)
{
var info = type.GetTypeInfo();
if (IsSimpleType(info))
{
var serializer = factory.GetSerializer(type);
return new ValueElement(type, serializer);
}
if (IsListType(info))
{
return new ListElement(type, catalog, factory);
}
return BuildSerializationObject(type, catalog, factory);
}
private static ISerializationElement BuildSerializationObject(Type type, IDictionary<Type, ISerializationElement> catalog, IObjectSerializerFactory factory)
{
if (catalog.TryGetValue(type, out var existing))
{
return existing;
}
var info = type.GetTypeInfo();
var contract = info.GetCustomAttribute<DataContractAttribute>();
if (null == contract)
{
throw new Exception();
}
var properties = new List<PropertyElement>();
var element = new ObjectElement(type, properties);
catalog.Add(type, element);
foreach (var property in info.DeclaredProperties)
{
var attribute = property.GetCustomAttribute<DataMemberAttribute>();
if (null == attribute)
{
continue;
}
if (!property.CanRead || !property.CanWrite)
{
continue;
}
var prop = new PropertyElement(property, CreateSerializationElement(property.PropertyType, catalog, factory));
properties.Add(prop);
}
properties.Sort(new ObjectPropertyComparer());
return element;
}
private static bool IsSimpleType(TypeInfo typeInfo)
{
if (typeInfo.IsValueType || typeInfo.IsEnum || typeInfo.IsPrimitive)
{
return true;
}
if (typeof (String) == typeInfo.AsType())
{
return true;
}
return false;
}
private static bool IsListType(TypeInfo typeInfo)
{
return typeof(IEnumerable).IsAssignableFrom(typeInfo);
}
}
}

@ -1,9 +0,0 @@
using System;
namespace Hessian.Net
{
public sealed class HessianSerializerException : Exception
{
}
}

@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hessian.Net
{
public class HessianSerializerSettings
{
}
}

@ -1,9 +0,0 @@
namespace Hessian.Net
{
public interface IObjectSerializer
{
void Serialize(HessianOutputWriter writer, object graph);
object Deserialize(HessianInputReader reader);
}
}

@ -1,9 +0,0 @@
using System;
namespace Hessian.Net
{
public interface IObjectSerializerFactory
{
IObjectSerializer GetSerializer(Type target);
}
}

@ -1,16 +0,0 @@
using System;
namespace Hessian.Net
{
public interface ISerializationElement
{
Type ObjectType
{
get;
}
void Serialize(HessianOutputWriter writer, object graph, HessianSerializationContext context);
object Deserialize(HessianInputReader reader, HessianSerializationContext context);
}
}

@ -1,162 +0,0 @@
using Hessian.Net.Specification;
namespace Hessian.Net
{
public class LeadingByte
{
public byte Data
{
get;
private set;
}
public bool IsNull => Check(If.Marker.Equals(Marker.Null));
public bool IsTrue => Check(If.Marker.Equals(Marker.True));
public bool IsFalse => Check(If.Marker.Equals(Marker.False));
public bool IsTinyInt32 => Check(If.Marker.Between(0x80).And(0xBF));
public bool IsShortInt32 => Check(If.Marker.Between(0xC0).And(0xCF));
public bool IsCompactInt32 => Check(If.Marker.Between(0xD0).And(0xD7));
public bool IsUnpackedInt32 => Check(If.Marker.Equals(Marker.UnpackedInteger));
public bool IsTinyInt64 => Check(If.Marker.Between(0xD8).And(0xEF));
public bool IsShortInt64 => Check(If.Marker.Between(0xF0).And(0xFF));
public bool IsCompactInt64 => Check(If.Marker.Between(0x38).And(0x3F));
public bool IsPackedInt64 => Check(If.Marker.Equals(Marker.PackedLong));
public bool IsUnpackedInt64 => Check(If.Marker.Equals(Marker.UnpackedLong));
public bool IsCompactBinary => Check(If.Marker.Between(0x20).And(0x2f));
public bool IsNonfinalChunkBinary => Check(If.Marker.Equals(Marker.BinaryNonfinalChunk));
public bool IsFinalChunkBinary => Check(If.Marker.Equals(Marker.BinaryFinalChunk));
public bool IsZeroDouble => Check(If.Marker.Equals(Marker.DoubleZero));
public bool IsOneDouble => Check(If.Marker.Equals(Marker.DoubleOne));
public bool IsTinyDouble => Check(If.Marker.Equals(Marker.DoubleOctet));
public bool IsShortDouble => Check(If.Marker.Equals(Marker.DoubleShort));
public bool IsCompactDouble => Check(If.Marker.Equals(Marker.DoubleFloat));
public bool IsUnpackedDouble => Check(If.Marker.Equals(Marker.Double));
public bool IsTinyString => Check(If.Marker.Between(0x00).And(0x1F));
public bool IsCompactString => Check(If.Marker.Between(0x30).And(0x33));
public bool IsNonfinalChunkString => Check(If.Marker.Equals(Marker.StringNonfinalChunk));
public bool IsFinalChunkString => Check(If.Marker.Equals(Marker.StringFinalChunk));
public bool IsCompactDateTime => Check(If.Marker.Equals(Marker.DateTimeCompact));
public bool IsUnpackedDateTime => Check(If.Marker.Equals(Marker.DateTimeLong));
public bool IsClassDefinition => Check(If.Marker.Equals(Marker.ClassDefinition));
public bool IsShortObjectReference => Check(If.Marker.Between(0x60).And(0x6F));
public bool IsLongObjectReference => Check(If.Marker.Equals(Marker.ClassReference));
public bool IsInstanceReference => Check(If.Marker.Equals(Marker.InstanceReference));
public bool IsVarList => Check(If.Marker.Equals(Marker.VarList));
public bool IsFixedList => Check(If.Marker.Equals(Marker.FixedList));
public bool IsVarListUntyped => Check(If.Marker.Equals(Marker.VarListUntyped));
public bool IsFixListUntyped => Check(If.Marker.Equals(Marker.FixListUntyped));
public bool IsCompactFixList => Check(If.Marker.Between(Marker.CompactFixListStart).And(Marker.CompactFixListEnd));
public bool IsCompactFixListUntyped => Check(If.Marker.Between(Marker.CompactFixListUntypedStart).And(Marker.CompactFixListUntypedEnd));
public void SetData(byte value)
{
Data = value;
}
private bool Check(ISpecification<byte> specification)
{
return specification.IsSatisfied(Data);
}
private static class If
{
internal static class Marker
{
public static MarkerValue Equals(byte value)
{
return new MarkerValue(value);
}
public static MarkerMinValue Between(byte value)
{
return new MarkerMinValue(value);
}
internal abstract class MarkerSpecification : ISpecification<byte>
{
public abstract bool IsSatisfied(byte arg);
}
internal class MarkerValue : MarkerSpecification
{
protected readonly byte value;
public MarkerValue(byte value)
{
this.value = value;
}
public override bool IsSatisfied(byte arg)
{
return value == arg;
}
}
internal class MarkerMinValue : MarkerValue
{
public MarkerMinValue(byte value)
: base(value)
{
}
public override bool IsSatisfied(byte arg)
{
return value <= arg;
}
public ISpecification<byte> And(byte max)
{
return this.And(new MarkerMaxValue(max));
}
}
private class MarkerMaxValue : MarkerValue
{
public MarkerMaxValue(byte value)
: base(value)
{
}
public override bool IsSatisfied(byte arg)
{
return value >= arg;
}
}
}
}
}
}

@ -1,179 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace Hessian.Net
{
public class ListElement: ISerializationElement
{
private readonly IDictionary<Type, ISerializationElement> _catalog;
private readonly IObjectSerializerFactory _factory;
public ListElement(Type listType, IDictionary<Type, ISerializationElement> catalog, IObjectSerializerFactory factory)
{
this.ObjectType = listType;
this._catalog = catalog;
this._factory = factory;
}
private readonly Lazy<ListTypeResolver> listTypeResolver = new Lazy<ListTypeResolver>();
public Type ObjectType { get; }
public ISerializationElement ChildSerializationElement { get; }
public void Serialize(HessianOutputWriter writer, object graph, HessianSerializationContext context)
{
throw new NotImplementedException();
}
public object Deserialize(HessianInputReader reader, HessianSerializationContext context)
{
object ret=null;
var preamble = reader.BeginList();
switch (preamble)
{
case ObjectPreamble.FixList:
ret =ReadFixList(reader, context);
break;
case ObjectPreamble.VarList:
ret = ReadVarList(reader, context);
break;
case ObjectPreamble.FixListUntyped:
ret = ReadFixListUntyped(reader, context);
break;
case ObjectPreamble.VarListUntyped:
ret = ReadVarListUntyped(reader, context);
break;
case ObjectPreamble.CompactFixList:
ret = ReadCompactFixList(reader, context);
break;
case ObjectPreamble.CompactFixListUntyped:
ret = ReadCompactFixListUntyped(reader, context);
break;
}
reader.EndList();
return ret;
}
private string ReadTypeName(HessianInputReader reader)
{
var tag = reader.Peek();
// A type name is either a string, or an integer reference to a
// string already read and stored in the type-name ref map.
if ((tag >= 0x00 && tag < 0x20)
|| (tag >= 0x30 && tag < 0x34)
|| tag == 0x52
|| tag == 0x53) {
var typeName = reader.ReadString();
return typeName;
}
reader.ReadInt32();
return "";
}
#region List
private IList<object> ReadVarList(HessianInputReader reader, HessianSerializationContext context)
{
var type = ReadTypeName(reader);
return ReadListCore(reader, context, type: type);
}
private IList<object> ReadFixList(HessianInputReader reader, HessianSerializationContext context)
{
var type = ReadTypeName(reader);
var length = reader.ReadInt32();
return ReadListCore(reader, context, length, type);
}
private IList<object> ReadVarListUntyped(HessianInputReader reader, HessianSerializationContext context)
{
return ReadListCore(reader, context);
}
private IList<object> ReadFixListUntyped(HessianInputReader reader, HessianSerializationContext context)
{
var length = reader.ReadInt32();
return ReadListCore(reader, context, length);
}
private IList<object> ReadCompactFixList(HessianInputReader reader, HessianSerializationContext context)
{
var tag = reader.LeadingByte.Data;
var length = tag - 0x70;
var type = ReadTypeName(reader);
return ReadListCore(reader, context, length, type);
}
private IList<object> ReadCompactFixListUntyped(HessianInputReader reader, HessianSerializationContext context)
{
var tag = reader.LeadingByte.Data;
var length = tag - 0x70;
return ReadListCore(reader, context, length);
}
private IList<object> ReadListCore(HessianInputReader reader, HessianSerializationContext context, int? length = null, string type = null)
{
var list = GetListInstance(type, length);
//objectRefs.Add(list);
if (length.HasValue) {
PopulateFixLengthList(reader, context, list, length.Value);
} else {
PopulateVarList(reader, context, list);
}
return list;
}
private IList<object> GetListInstance(string type, int? length = null)
{
IList<object> list;
if (length.HasValue) {
if (!listTypeResolver.Value.TryGetListInstance(type, length.Value, out list)) {
list = new List<object>(length.Value);
}
} else {
if (!listTypeResolver.Value.TryGetListInstance(type, out list)) {
list = new List<object>();
}
}
return list;
}
private void PopulateFixLengthList(HessianInputReader reader, HessianSerializationContext context, IList<object> list, int length)
{
var tag = reader.ReadByte(); //0x16
for (var i = 0; i < length; ++i)
{
ObjectElement objectElement = new ObjectElement();
var scheme = HessianSerializationScheme.CreateFromType(this.GetType(), this._factory);
var obj = scheme.Deserialize(reader, context);
list.Add(obj);
}
}
private void PopulateVarList(HessianInputReader reader, HessianSerializationContext context, IList<object> list)
{
while (true) {
var tag = reader.ReadByte();
if (tag == 'Z') {
reader.ReadByte();
break;
}
list.Add(this.ChildSerializationElement.Deserialize(reader, context));
}
}
#endregion
}
}

@ -1,66 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
namespace Hessian.Net
{
public class ListTypeResolver
{
private readonly Dictionary<string, Func<IList<object>>> constructors = new Dictionary<string, Func<IList<object>>>();
private readonly Dictionary<string, Func<int, IList<object>>> length_constructors = new Dictionary<string, Func<int, IList<object>>>();
private readonly Func<IList<object>> empty_list_ctor = () => new List<object>();
private readonly Func<int, IList<object>> empty_list_ctor_with_length = length => new List<object>(length);
public ListTypeResolver()
{
constructors.Add("System.Collections.ArrayList", empty_list_ctor);
constructors.Add("System.Collections.List", empty_list_ctor);
constructors.Add("System.Collections.IList", empty_list_ctor);
constructors.Add("System.Collections.Generic.List`1", empty_list_ctor);
constructors.Add("System.Collections.Generic.IList`1", empty_list_ctor);
constructors.Add("System.Collections.ObjectModel.Collection`1", () => new Collection<object>());
constructors.Add("java.util.List", empty_list_ctor);
constructors.Add("java.util.Vector", empty_list_ctor);
constructors.Add("java.util.ArrayList", empty_list_ctor);
constructors.Add("java.util.LinkedList", empty_list_ctor);
length_constructors.Add("System.Collections.List", empty_list_ctor_with_length);
length_constructors.Add("System.Collections.IList", empty_list_ctor_with_length);
length_constructors.Add("System.Collections.Generic.List`1", empty_list_ctor_with_length);
length_constructors.Add("System.Collections.Generic.IList`1", empty_list_ctor_with_length);
length_constructors.Add("java.util.List", empty_list_ctor_with_length);
length_constructors.Add("java.util.Vector", empty_list_ctor_with_length);
length_constructors.Add("java.util.ArrayList", empty_list_ctor_with_length);
length_constructors.Add("java.util.LinkedList", empty_list_ctor_with_length);
}
public bool TryGetListInstance(string type, out IList<object> list)
{
list = null;
Func<IList<object>> ctor;
if (!constructors.TryGetValue(type, out ctor))
{
return false;
}
list = ctor();
return true;
}
public bool TryGetListInstance(string type, int length, out IList<object> list)
{
list = null;
Func<int, IList<object>> ctor;
if (!length_constructors.TryGetValue(type, out ctor))
{
return false;
}
list = ctor(length);
return true;
}
}
}

@ -1,42 +0,0 @@
namespace Hessian.Net
{
/// <summary>
///
/// </summary>
internal static class Marker
{
public const byte True = (byte) 'T';//0x54;
public const byte False = (byte) 'F';// 0x46;
public const byte Null = (byte) 'N';//0x4E;
public const byte BinaryNonfinalChunk = (byte) 'b';//0x41;
public const byte BinaryFinalChunk = (byte) 'B';//0x42;
public const byte ClassDefinition = (byte) 'C';//0x43;
public const byte DateTimeLong = 0x4A;
public const byte DateTimeCompact = 0x4B;
public const byte Double = 0x5A;
public const byte DoubleZero = 0x5B;
public const byte DoubleOne = 0x5C;
public const byte DoubleOctet = 0x5D;
public const byte DoubleShort = 0x5E;
public const byte DoubleFloat = 0x5F;
public const byte UnpackedInteger = (byte) 'I';// 0x49;
public const byte PackedLong = (byte) 'Y';// 0x59;
public const byte UnpackedLong = (byte) 'L';// 0x4C;
public const byte StringNonfinalChunk = 0x52;
public const byte StringFinalChunk = 0x53;
public const byte VarList = 0x55;
public const byte FixedList = 0x56;
public const byte VarListUntyped = 0x57;
public const byte FixListUntyped = 0x58;
public const byte CompactFixListStart = 0x70;
public const byte CompactFixListEnd = 0x77;
public const byte CompactFixListUntypedStart = 0x78;
public const byte CompactFixListUntypedEnd = 0x7F;
public const byte ClassReference = (byte) 'O';//0x4F
public const byte InstanceReference = (byte) 'Q'; //0x51;
}
}

@ -1,153 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using Hessian.Net.Extension;
namespace Hessian.Net
{
public class ObjectElement : ISerializationElement
{
private string classname;
public Type ObjectType
{
get;
}
public string ClassName
{
get
{
if (String.IsNullOrEmpty(classname))
{
classname = ObjectType
.GetTypeInfo()
.GetCustomAttribute<DataContractAttribute>()
.Unless(attribute => String.IsNullOrEmpty(attribute.Name))
.Return(attribute => attribute.Name, ObjectType.FullName);
}
return classname;
}
}
public IList<PropertyElement> ObjectProperties
{
get;
}
public ObjectElement()
{
}
public ObjectElement(Type objectType, IList<PropertyElement> objectProperties)
{
ObjectType = objectType;
ObjectProperties = objectProperties;
}
public void Serialize(HessianOutputWriter writer, object graph, HessianSerializationContext context)
{
var index = context.Instances.IndexOf(graph);
if (index > -1)
{
writer.WriteInstanceReference(index);
return;
}
context.Instances.Add(graph);
index = context.Classes.IndexOf(ObjectType);
if (index < 0)
{
writer.BeginClassDefinition();
writer.WriteString(ClassName);
writer.WriteInt32(ObjectProperties.Count);
foreach (var property in ObjectProperties)
{
writer.WriteString(property.PropertyName);
}
writer.EndClassDefinition();
index = context.Classes.Count;
context.Classes.Add(ObjectType);
}
writer.WriteObjectReference(index);
foreach (var item in ObjectProperties)
{
var value = item.Property.GetValue(graph);
item.Serialize(writer, value, context);
}
}
public object Deserialize(HessianInputReader reader, HessianSerializationContext context)
{
reader.BeginObject();
if (reader.IsClassDefinition)
{
var className = reader.ReadString();
var propertiesCount = reader.ReadInt32();
if (!String.Equals(this.ClassName, className))
{
throw new HessianSerializerException();
}
if (this.ObjectProperties.Count != propertiesCount)
{
throw new HessianSerializerException();
}
for (var index = 0; index < propertiesCount; index++)
{
var propertyName = reader.ReadString();
var exists = this.ObjectProperties.Any(property => String.Equals(property.PropertyName, propertyName));
if (!exists)
{
throw new HessianSerializerException();
}
}
context.Classes.Add(this.ObjectType);
reader.EndClassDefinition();
}
else if (reader.IsInstanceReference)
{
var index = reader.ReadInstanceReference();
return context.Instances[index];
}
var number = reader.ReadObjectReference();
var instance = Activator.CreateInstance(this.ObjectType);
context.Instances.Add(instance);
foreach (var item in this.ObjectProperties)
{
Console.WriteLine(item.PropertyName);
var value = item.Deserialize(reader, context);
Console.WriteLine(value);
item.Property.SetValue(instance, value);
}
reader.EndObject();
return instance;
}
}
}

@ -1,17 +0,0 @@
namespace Hessian.Net
{
public enum ObjectPreamble
{
None = -1,
ClassDefinition,
ObjectReference,
InstanceReference,
VarList,
FixList,
VarListUntyped,
FixListUntyped,
CompactFixList,
CompactFixListUntyped
}
}

@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
namespace Hessian.Net
{
internal class ObjectPropertyComparer : IComparer<PropertyElement>
{
private readonly IComparer<int> comparer;
public ObjectPropertyComparer()
{
comparer = Comparer<int>.Default;
}
public int Compare(PropertyElement x, PropertyElement y)
{
var eq = comparer.Compare(x.PropertyOrder, y.PropertyOrder);
return 0 == eq
? String.Compare(x.PropertyName, y.PropertyName, StringComparison.Ordinal)
: eq;
}
}
}

@ -1,71 +0,0 @@
using System;
using System.Reflection;
using System.Runtime.Serialization;
using Hessian.Net.Extension;
namespace Hessian.Net
{
public class PropertyElement : ISerializationElement
{
private string propertyname;
private int? propertyOrder;
public Type ObjectType => Property.PropertyType;
public PropertyInfo Property
{
get;
}
public ISerializationElement Element
{
get;
}
public int PropertyOrder
{
get
{
if (!propertyOrder.HasValue)
{
var attribute = Property.GetCustomAttribute<DataMemberAttribute>();
propertyOrder = null == attribute ? 0 : attribute.Order;
}
return propertyOrder.Value;
}
}
public string PropertyName
{
get
{
if (String.IsNullOrEmpty(propertyname))
{
propertyname = Property
.GetCustomAttribute<DataMemberAttribute>()
.Unless(attribute => String.IsNullOrEmpty(attribute.Name))
.Return(attribute => attribute.Name, Property.Name);
}
return propertyname;
}
}
public PropertyElement(PropertyInfo property, ISerializationElement element)
{
Property = property;
Element = element;
}
public void Serialize(HessianOutputWriter writer, object graph, HessianSerializationContext context)
{
Element.Serialize(writer, graph, context);
}
public object Deserialize(HessianInputReader reader, HessianSerializationContext context)
{
return Element.Deserialize(reader, context);
}
}
}

@ -1,15 +0,0 @@
namespace Hessian.Net.Specification
{
internal class AndSpecification<TParam> : BinarySpecification<TParam>
{
public AndSpecification(ISpecification<TParam> left, ISpecification<TParam> right)
: base(left, right)
{
}
public override bool IsSatisfied(TParam arg)
{
return Left.IsSatisfied(arg) && Right.IsSatisfied(arg);
}
}
}

@ -1,25 +0,0 @@
namespace Hessian.Net.Specification
{
public abstract class BinarySpecification<TParam> : ISpecification<TParam>
{
public ISpecification<TParam> Left
{
get;
protected set;
}
public ISpecification<TParam> Right
{
get;
protected set;
}
protected BinarySpecification(ISpecification<TParam> left, ISpecification<TParam> right)
{
Left = left;
Right = right;
}
public abstract bool IsSatisfied(TParam arg);
}
}

@ -1,16 +0,0 @@
namespace Hessian.Net.Specification
{
/// <summary>
///
/// </summary>
/// <typeparam name="TParam"></typeparam>
public interface ISpecification<in TParam>
{
/// <summary>
/// Checks if current specification can be satisfied by given <paramref name="arg" />
/// </summary>
/// <param name="arg">The value to check specification</param>
/// <returns>Flags if specification is satisfied successfuly</returns>
bool IsSatisfied(TParam arg);
}
}

@ -1,17 +0,0 @@
namespace Hessian.Net.Specification
{
public class NotSpecification<TParam> : ISpecification<TParam>
{
private readonly ISpecification<TParam> specification;
public NotSpecification(ISpecification<TParam> specification)
{
this.specification = specification;
}
public bool IsSatisfied(TParam arg)
{
return !specification.IsSatisfied(arg);
}
}
}

@ -1,29 +0,0 @@
namespace Hessian.Net.Specification
{
/// <summary>
///
/// </summary>
/// <typeparam name="TParam"></typeparam>
public class OrSpecification<TParam> : BinarySpecification<TParam>
{
/// <summary>
///
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
public OrSpecification(ISpecification<TParam> left, ISpecification<TParam> right)
: base(left, right)
{
}
/// <summary>
///
/// </summary>
/// <param name="arg"></param>
/// <returns></returns>
public override bool IsSatisfied(TParam arg)
{
return Left.IsSatisfied(arg) || Right.IsSatisfied(arg);
}
}
}

@ -1,19 +0,0 @@
namespace Hessian.Net.Specification
{
/// <summary>
///
/// </summary>
public static class Specification
{
/// <summary>
///
/// </summary>
/// <typeparam name="TParam"></typeparam>
/// <param name="specification"></param>
/// <returns></returns>
public static ISpecification<TParam> Not<TParam>(ISpecification<TParam> specification)
{
return new NotSpecification<TParam>(specification);
}
}
}

@ -1,32 +0,0 @@
namespace Hessian.Net.Specification
{
/// <summary>
///
/// </summary>
public static class SpecificationExtension
{
/// <summary>
///
/// </summary>
/// <typeparam name="TParam"></typeparam>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static ISpecification<TParam> And<TParam>(this ISpecification<TParam> left, ISpecification<TParam> right)
{
return new AndSpecification<TParam>(left, right);
}
/// <summary>
///
/// </summary>
/// <typeparam name="TParam"></typeparam>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static ISpecification<TParam> Or<TParam>(this ISpecification<TParam> left, ISpecification<TParam> right)
{
return new OrSpecification<TParam>(left, right);
}
}
}

@ -1,23 +0,0 @@
using System;
namespace Hessian.Net
{
internal static class Throw
{
public static void NotNull(object arg, string argname)
{
if (null == arg)
{
throw new ArgumentNullException(argname);
}
}
public static void Validate(Func<bool> validator, string argname)
{
if (!validator())
{
throw new ArgumentException("", argname);
}
}
}
}

@ -1,10 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Hessian.NET
{
class TypeResolver
{
}
}

@ -1,33 +0,0 @@
using System;
namespace Hessian.Net
{
public class ValueElement : ISerializationElement
{
public Type ObjectType
{
get;
}
public IObjectSerializer ObjectSerializer
{
get;
}
public ValueElement(Type objectType, IObjectSerializer objectSerializer)
{
ObjectType = objectType;
ObjectSerializer = objectSerializer;
}
public void Serialize(HessianOutputWriter writer, object graph, HessianSerializationContext context)
{
ObjectSerializer.Serialize(writer, graph);
}
public object Deserialize(HessianInputReader reader, HessianSerializationContext context)
{
return ObjectSerializer.Deserialize(reader);
}
}
}

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.NetworkInformation;
using System.Text;
using Hessian.Collections;
@ -47,127 +48,127 @@ namespace Hessian
if (!tag.HasValue) {
throw new EndOfStreamException();
}
Console.WriteLine("------------ 0x{0:x2}----------------",tag.Value);
//Console.WriteLine("------------ 0x{0:x2}----------------",tag.Value);
switch (tag.Value) {
case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:
case 0x08: case 0x09: case 0x0A: case 0x0B: case 0x0C: case 0x0D: case 0x0E: case 0x0F:
case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17:
case 0x18: case 0x19: case 0x1A: case 0x1B: case 0x1C: case 0x1D: case 0x1E: case 0x1F:
Console.WriteLine("ReadShortString");
//Console.WriteLine("ReadShortString");
return ReadShortString();
case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27:
case 0x28: case 0x29: case 0x2A: case 0x2B: case 0x2C: case 0x2D: case 0x2E: case 0x2F:
Console.WriteLine("ReadShortBinary");
//Console.WriteLine("ReadShortBinary");
return ReadShortBinary();
case 0x30: case 0x31: case 0x32: case 0x33:
Console.WriteLine("ReadMediumString");
//Console.WriteLine("ReadMediumString");
return ReadMediumString();
case 0x34: case 0x35: case 0x36: case 0x37:
Console.WriteLine("ReadMediumBinary");
//Console.WriteLine("ReadMediumBinary");
return ReadMediumBinary();
case 0x38: case 0x39: case 0x3A: case 0x3B: case 0x3C: case 0x3D: case 0x3E: case 0x3F:
Console.WriteLine("ReadLongThreeBytes");
//Console.WriteLine("ReadLongThreeBytes");
return ReadLongThreeBytes();
case 0x40:
Console.WriteLine("Reserved");
//Console.WriteLine("Reserved");
return Reserved();
case 0x41: case 0x42:
Console.WriteLine("ReadChunkedBinary");
//Console.WriteLine("ReadChunkedBinary");
return ReadChunkedBinary();
case 0x43:
Console.WriteLine("ReadClassDefinition");
//Console.WriteLine("ReadClassDefinition");
return ReadClassDefinition();
case 0x44:
Console.WriteLine("ReadFullDouble");
//Console.WriteLine("ReadFullDouble");
return ReadFullDouble();
case 0x45:
Console.WriteLine("Reserved");
//Console.WriteLine("Reserved");
return Reserved();
case 0x46:
Console.WriteLine("ReadBoolean");
//Console.WriteLine("ReadBoolean");
return ReadBoolean();
case 0x47:
Console.WriteLine("Reserved");
//Console.WriteLine("Reserved");
return Reserved();
case 0x48:
Console.WriteLine("ReadUntypedMap");
//Console.WriteLine("ReadUntypedMap");
return ReadUntypedMap();
case 0x49:
Console.WriteLine("ReadInteger");
//Console.WriteLine("ReadInteger");
return ReadInteger();
case 0x4A:
Console.WriteLine("ReadDateInMillis");
//Console.WriteLine("ReadDateInMillis");
return ReadDateInMillis();
case 0x4B:
Console.WriteLine("ReadDateInMinutes");
//Console.WriteLine("ReadDateInMinutes");
return ReadDateInMinutes();
case 0x4C:
Console.WriteLine("ReadLongFull");
//Console.WriteLine("ReadLongFull");
return ReadLongFull();
case 0x4D:
Console.WriteLine("ReadTypedMap");
//Console.WriteLine("ReadTypedMap");
return ReadTypedMap();
case 0x4E:
Console.WriteLine("ReadNull");
//Console.WriteLine("ReadNull");
return ReadNull();
case 0x4F:
Console.WriteLine("ReadObject");
//Console.WriteLine("ReadObject");
return ReadObject();
case 0x50:
Console.WriteLine("Reserved");
//Console.WriteLine("Reserved");
return Reserved();
case 0x51:
Console.WriteLine("ReadRef");
//Console.WriteLine("ReadRef");
return ReadRef();
case 0x52: case 0x53:
Console.WriteLine("ReadChunkedString");
//Console.WriteLine("ReadChunkedString");
return ReadChunkedString();
case 0x54:
Console.WriteLine("ReadBoolean");
//Console.WriteLine("ReadBoolean");
return ReadBoolean();
case 0x55:
Console.WriteLine("ReadVarList");
//Console.WriteLine("ReadVarList");
return ReadVarList();
case 0x56:
Console.WriteLine("ReadFixList");
//Console.WriteLine("ReadFixList");
return ReadFixList();
case 0x57:
Console.WriteLine("ReadVarListUntyped");
//Console.WriteLine("ReadVarListUntyped");
return ReadVarListUntyped();
case 0x58:
Console.WriteLine("ReadFixListUntyped");
//Console.WriteLine("ReadFixListUntyped");
return ReadFixListUntyped();
case 0x59:
Console.WriteLine("ReadLongFourBytes");
//Console.WriteLine("ReadLongFourBytes");
return ReadLongFourBytes();
case 0x5A:
@ -175,32 +176,32 @@ namespace Hessian
throw new UnexpectedTagException(0x5A, "value");
case 0x5B: case 0x5C:
Console.WriteLine("ReadDoubleOneByte");
//Console.WriteLine("ReadDoubleOneByte");
return ReadDoubleOneByte();
case 0x5D:
Console.WriteLine("ReadDoubleOneByte");
//Console.WriteLine("ReadDoubleOneByte");
return ReadDoubleOneByte();
case 0x5E:
Console.WriteLine("ReadDoubleTwoBytes");
//Console.WriteLine("ReadDoubleTwoBytes");
return ReadDoubleTwoBytes();
case 0x5F:
Console.WriteLine("ReadDoubleFourBytes");
//Console.WriteLine("ReadDoubleFourBytes");
return ReadDoubleFourBytes();
case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67:
case 0x68: case 0x69: case 0x6A: case 0x6B: case 0x6C: case 0x6D: case 0x6E: case 0x6F:
Console.WriteLine("ReadObjectCompact");
//Console.WriteLine("ReadObjectCompact");
return ReadObjectCompact();
case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77:
Console.WriteLine("ReadCompactFixList");
//Console.WriteLine("ReadCompactFixList");
return ReadCompactFixList();
case 0x78: case 0x79: case 0x7A: case 0x7B: case 0x7C: case 0x7D: case 0x7E: case 0x7F:
Console.WriteLine("ReadCompactFixListUntyped");
//Console.WriteLine("ReadCompactFixListUntyped");
return ReadCompactFixListUntyped();
case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87:
@ -211,27 +212,27 @@ namespace Hessian
case 0xA8: case 0xA9: case 0xAA: case 0xAB: case 0xAC: case 0xAD: case 0xAE: case 0xAF:
case 0xB0: case 0xB1: case 0xB2: case 0xB3: case 0xB4: case 0xB5: case 0xB6: case 0xB7:
case 0xB8: case 0xB9: case 0xBA: case 0xBB: case 0xBC: case 0xBD: case 0xBE: case 0xBF:
Console.WriteLine("ReadIntegerSingleByte");
//Console.WriteLine("ReadIntegerSingleByte");
return ReadIntegerSingleByte();
case 0xC0: case 0xC1: case 0xC2: case 0xC3: case 0xC4: case 0xC5: case 0xC6: case 0xC7:
case 0xC8: case 0xC9: case 0xCA: case 0xCB: case 0xCC: case 0xCD: case 0xCE: case 0xCF:
Console.WriteLine("ReadIntegerTwoBytes");
//Console.WriteLine("ReadIntegerTwoBytes");
return ReadIntegerTwoBytes();
case 0xD0: case 0xD1: case 0xD2: case 0xD3: case 0xD4: case 0xD5: case 0xD6: case 0xD7:
Console.WriteLine("ReadIntegerThreeBytes");
//Console.WriteLine("ReadIntegerThreeBytes");
return ReadIntegerThreeBytes();
case 0xD8: case 0xD9: case 0xDA: case 0xDB: case 0xDC: case 0xDD: case 0xDE: case 0xDF:
case 0xE0: case 0xE1: case 0xE2: case 0xE3: case 0xE4: case 0xE5: case 0xE6: case 0xE7:
case 0xE8: case 0xE9: case 0xEA: case 0xEB: case 0xEC: case 0xED: case 0xEE: case 0xEF:
Console.WriteLine("ReadLongOneByte");
//Console.WriteLine("ReadLongOneByte");
return ReadLongOneByte();
case 0xF0: case 0xF1: case 0xF2: case 0xF3: case 0xF4: case 0xF5: case 0xF6: case 0xF7:
case 0xF8: case 0xF9: case 0xFA: case 0xFB: case 0xFC: case 0xFD: case 0xFE: case 0xFF:
Console.WriteLine("ReadLongTwoBytes");
//Console.WriteLine("ReadLongTwoBytes");
return ReadLongTwoBytes();
}
@ -255,6 +256,7 @@ namespace Hessian
|| tag == 0x52
|| tag == 0x53) {
var typeName = ReadString();
//Console.WriteLine("Type={0}",typeName);
typeNameRefs.Add(typeName);
return typeName;
}
@ -340,9 +342,59 @@ namespace Hessian
private void PopulateFixLengthList(IList<object> list, int length)
{
for (var i = 0; i < length; ++i) {
list.Add(ReadValue());
// NOTE: 这里有BUG 第一层 如果是复杂对象 那第一个readValue的
// 结果是 classDef,下一个才是真实的数据,但是如果数据的字段又是复杂类型
// 下一个 就还是classDef 接着是真实数据,以此类型,但是呢,如果类型之前
for (var i = 0; i < length; ++i)
{
var obj = ReadValue();
switch (obj)
{
case ClassDef _:
{
var rVal = ReadValue() as HessianObject; // 真实的数据
if (rVal == null)
{
throw new HessianException("decode error");
}
list.Add(ReadRealObject(rVal));
break;
}
case HessianObject vObj:
list.Add(ReadRealObject(vObj));
break;
default:
list.Add(obj);
break;
}
}
}
private HessianObject ReadRealObject(HessianObject hessianObject)
{
var builder = HessianObject.Builder.New(hessianObject.TypeName);
foreach (var (k,v) in hessianObject)
{
if (v is ClassDef)
{
if (!(ReadValue() is HessianObject rVal))
{
throw new HessianException("decode error");
}
builder.Add(k,ReadRealObject(rVal));
}
else if(v is HessianObject vObj)
{
builder.Add(k,ReadRealObject(vObj));
}
else
{
builder.Add(k, v);
}
}
return builder.Create();
}
private void PopulateVarList(IList<object> list)

@ -112,6 +112,7 @@ namespace Hessian
WriteString("["+GetItemTypeName(item.GetType()));
}
WriteValue(item);
index++;
}
}
@ -123,6 +124,11 @@ namespace Hessian
return classType.Name;
}
if (IsListType(type.GetTypeInfo()))
{
return "java.util.List";
}
return type.Name;
}
private void WriteSimpleValue(object val)

Loading…
Cancel
Save