Permalink
Browse files

file headers

  • Loading branch information...
1 parent 2e1653f commit 6bf0b8fafdc90cfe6257b7c44f3206e9f6e17b58 @rogeralsing committed Dec 6, 2016
Showing with 1,289 additions and 653 deletions.
  1. +9 −7 README.md
  2. +0 −2 RELEASE_NOTES.md
  3. +7 −1 Wire/ByteArrayKey.cs
  4. +10 −4 Wire/ByteArrayKeyComparer.cs
  5. +17 −11 Wire/Compilation/Compiler.cs
  6. +9 −3 Wire/Compilation/ExpressionEx.cs
  7. +7 −1 Wire/Compilation/ICompiler.cs
  8. +7 −1 Wire/Compilation/IlBuilder.cs
  9. +7 −1 Wire/Compilation/IlCompiler.cs
  10. +9 −2 Wire/Compilation/IlCompilerContext.cs
  11. +23 −15 Wire/Compilation/IlExpression.cs
  12. +13 −4 Wire/DefaultCodeGenerator.cs
  13. +7 −1 Wire/Delegates.cs
  14. +21 −15 Wire/DeserializeSession.cs
  15. +7 −1 Wire/Extensions/ReflectionEx.cs
  16. +22 −17 Wire/Extensions/StreamEx.cs
  17. +8 −3 Wire/Extensions/StringEx.cs
  18. +15 −10 Wire/Extensions/TypeEx.cs
  19. +6 −0 Wire/ICodeGenerator.cs
  20. +488 −316 Wire/Internal/Annotations.cs
  21. +18 −11 Wire/NoAllocBitConverter.cs
  22. +8 −1 Wire/Properties/AssemblyInfo.cs
  23. +16 −14 Wire/Serializer.cs
  24. +12 −5 Wire/SerializerFactories/ArraySerializerFactory.cs
  25. +11 −8 Wire/SerializerFactories/ConsistentArraySerializerFactory.cs
  26. +8 −2 Wire/SerializerFactories/ConstructorInfoSerializerFactory.cs
  27. +12 −7 Wire/SerializerFactories/DefaultDictionarySerializerFactory.cs
  28. +7 −1 Wire/SerializerFactories/DelegateSerializerFactory.cs
  29. +15 −6 Wire/SerializerFactories/DictionarySerializerFactory.cs
  30. +17 −10 Wire/SerializerFactories/EnumerableSerializerFactory.cs
  31. +18 −11 Wire/SerializerFactories/ExceptionSerializerFactory.cs
  32. +13 −10 Wire/SerializerFactories/ExpandoObjectSerializerFactory.cs
  33. +17 −7 Wire/SerializerFactories/FSharpListSerializerFactory.cs
  34. +17 −13 Wire/SerializerFactories/FSharpMapSerializerFactory.cs
  35. +11 −3 Wire/SerializerFactories/FieldInfoSerializerFactory.cs
  36. +10 −2 Wire/SerializerFactories/FromSurrogateSerializerFactory.cs
  37. +10 −3 Wire/SerializerFactories/ISerializableSerializerFactory.cs
  38. +17 −8 Wire/SerializerFactories/ImmutableCollectionsSerializerFactory.cs
  39. +9 −3 Wire/SerializerFactories/MethodInfoSerializerFactory.cs
  40. +11 −4 Wire/SerializerFactories/PropertyInfoSerializerFactory.cs
  41. +7 −2 Wire/SerializerFactories/ToSurrogateSerializerFactory.cs
  42. +7 −1 Wire/SerializerFactories/ValueSerializerFactory.cs
  43. +22 −14 Wire/SerializerOptions.cs
  44. +11 −5 Wire/SerializerSession.cs
  45. +9 −3 Wire/Surrogate.cs
  46. +6 −0 Wire/ValueSerializers/BoolSerializer.cs
  47. +8 −3 Wire/ValueSerializers/ByteArraySerializer.cs
  48. +7 −1 Wire/ValueSerializers/ByteSerializer.cs
  49. +9 −3 Wire/ValueSerializers/CharSerializer.cs
  50. +12 −5 Wire/ValueSerializers/ConsistentArraySerializer.cs
  51. +8 −2 Wire/ValueSerializers/DateTimeSerializer.cs
  52. +7 −2 Wire/ValueSerializers/DecimalSerializer.cs
  53. +9 −3 Wire/ValueSerializers/DoubleSerializer.cs
  54. +9 −3 Wire/ValueSerializers/FloatSerializer.cs
  55. +7 −1 Wire/ValueSerializers/FromSurrogateSerializer.cs
  56. +7 −1 Wire/ValueSerializers/GuidSerializer.cs
  57. +8 −2 Wire/ValueSerializers/Int16Serializer.cs
  58. +8 −2 Wire/ValueSerializers/Int32Serializer.cs
  59. +8 −2 Wire/ValueSerializers/Int64Serializer.cs
  60. +7 −1 Wire/ValueSerializers/KnownTypeObjectSerializer.cs
  61. +7 −1 Wire/ValueSerializers/NullSerializer.cs
  62. +8 −2 Wire/ValueSerializers/ObjectReferenceSerializer.cs
  63. +9 −3 Wire/ValueSerializers/ObjectSerializer.cs
  64. +7 −1 Wire/ValueSerializers/SByteSerializer.cs
  65. +8 −2 Wire/ValueSerializers/SessionAwareByteArrayRequiringValueSerializer.cs
  66. +9 −3 Wire/ValueSerializers/SessionIgnorantValueSerializer.cs
  67. +7 −1 Wire/ValueSerializers/StringSerializer.cs
  68. +9 −2 Wire/ValueSerializers/SystemObjectSerializer.cs
  69. +7 −1 Wire/ValueSerializers/ToSurrogateSerializer.cs
  70. +14 −8 Wire/ValueSerializers/TypeSerializer.cs
  71. +9 −3 Wire/ValueSerializers/UInt16Serializer.cs
  72. +9 −3 Wire/ValueSerializers/UInt32Serializer.cs
  73. +9 −4 Wire/ValueSerializers/UInt64Serializer.cs
  74. +24 −7 Wire/ValueSerializers/UnsupportedTypeSerializer.cs
  75. +16 −6 Wire/ValueSerializers/ValueSerializer.cs
  76. +12 −6 Wire/Wire.project.lock.json
View
@@ -1,8 +1,8 @@
# Wire
-[![Join the chat at https://gitter.im/akkadotnet/Wire](https://badges.gitter.im/akkadotnet/Wire.svg)](https://gitter.im/akkadotnet/Wire?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
+A high performance polymorphic serializer for the .NET framework.
-A high performance polymorphic serializer for the .NET framework.¨
+> Wire is still in beta and may have breaking changes to both the API and serialization format on the road to 1.0
## Polymorphic serializations
@@ -48,15 +48,17 @@ This is essential for frameworks like Akka.NET where we need to be able to resol
Wire has been designed to work in multiple modes in terms of version tolerance vs. performance.
1. Pre Register Types, when using "Pre registered types", Wire will only emit a type ID in the output stream.
-This results in the best performance, but is also fragile if different clients have different versions of the contract types.
+ This results in the best performance, but is also fragile if different clients have different versions of the contract types.
2. Non Versioned, this is largely the same as the above, but the serializer does not need to know about your types up front. it will embed the fully qualified typename
-in the outputstream. this results in a larger payload and some performance overhead.
+ in the outputstream. this results in a larger payload and some performance overhead.
3. Versioned, in this mode, Wire will emit both type names and field information in the output stream.
-This allows systems to have slightly different versions of the contract types where some fields may have been added or removed.
+ This allows systems to have slightly different versions of the contract types where some fields may have been added or removed.
+
+### Durable persistence and version tolerance
Wire has been designed as a wire format, point to point for soft realtime scenarios.
If you need a format that is durable for persistence over time.
-e.g. EventSourcing or for message queues, then Protobuf or MS Bond is probably a better choise as those formats have been designed for true versiom tolerance.
+e.g. EventSourcing or for message queues, then **Protobuf**, **Thrift**, **Flatbuffers** or **MS Bond** will be a better choise as those formats have been designed for true versiom tolerance.
## Performance
@@ -130,4 +132,4 @@ public class Poco
```
> Big disclaimer: The above results change drastically depending on your contracts, e.g. using smaller messages favor both NetSerializer and Jil.
-There is no "best" or "fastest" serializer, it all depends on context and requirements.
+> There is no "best" or "fastest" serializer, it all depends on context and requirements.
View
@@ -1,2 +0,0 @@
-### New in 0.9.0 (Released 2016/11/24)
-* TODO
@@ -1,9 +1,15 @@
+// //-----------------------------------------------------------------------
+// // <copyright file="ByteArrayKey.cs" company="Asynkron HB">
+// // Copyright (C) 2015-2016 Asynkron HB All rights reserved
+// // </copyright>
+// //-----------------------------------------------------------------------
+
using Wire.Internal;
namespace Wire
{
public struct ByteArrayKey
- {
+ {
public readonly byte[] Bytes;
private readonly int _hashCode;
@@ -1,10 +1,16 @@
-using System.Collections.Generic;
+// //-----------------------------------------------------------------------
+// // <copyright file="ByteArrayKeyComparer.cs" company="Asynkron HB">
+// // Copyright (C) 2015-2016 Asynkron HB All rights reserved
+// // </copyright>
+// //-----------------------------------------------------------------------
+
+using System.Collections.Generic;
namespace Wire
{
/// <summary>
- /// By default ByteArrayKey overrides "public bool Equals(object obj)" to do comparisons.
- /// But this causes boxing/allocations, so by having a custom comparer we can prevent that.
+ /// By default ByteArrayKey overrides "public bool Equals(object obj)" to do comparisons.
+ /// But this causes boxing/allocations, so by having a custom comparer we can prevent that.
/// </summary>
public class ByteArrayKeyComparer : IEqualityComparer<ByteArrayKey>
{
@@ -20,4 +26,4 @@ public int GetHashCode(ByteArrayKey obj)
return obj.GetHashCode();
}
}
-}
+}
@@ -1,3 +1,9 @@
+// //-----------------------------------------------------------------------
+// // <copyright file="Compiler.cs" company="Asynkron HB">
+// // Copyright (C) 2015-2016 Asynkron HB All rights reserved
+// // </copyright>
+// //-----------------------------------------------------------------------
+
using System;
using System.Collections.Generic;
using System.Linq;
@@ -36,7 +42,7 @@ public int Variable<T>(string name)
return _expressions.Count - 1;
}
- public int Variable(string name,Type type)
+ public int Variable(string name, Type type)
{
var exp = Expression.Variable(type, name);
_variables.Add(exp);
@@ -134,16 +140,6 @@ public int WriteField(FieldInfo field, int target, int value)
return _expressions.Count - 1;
}
- public Expression ToBlock()
- {
- if (!_content.Any())
- {
- _content.Add(Expression.Empty());
- }
-
- return Expression.Block(_variables.ToArray(), _content);
- }
-
public TDel Compile()
{
var body = ToBlock();
@@ -182,5 +178,15 @@ public int Convert(int value, Type type)
_expressions.Add(conv);
return _expressions.Count - 1;
}
+
+ public Expression ToBlock()
+ {
+ if (!_content.Any())
+ {
+ _content.Add(Expression.Empty());
+ }
+
+ return Expression.Block(_variables.ToArray(), _content);
+ }
}
}
@@ -1,4 +1,10 @@
-using System;
+// //-----------------------------------------------------------------------
+// // <copyright file="ExpressionEx.cs" company="Asynkron HB">
+// // Copyright (C) 2015-2016 Asynkron HB All rights reserved
+// // </copyright>
+// //-----------------------------------------------------------------------
+
+using System;
using System.Linq.Expressions;
using System.Reflection;
using Wire.Extensions;
@@ -17,7 +23,7 @@ public static Expression GetNewExpression(Type type)
{
if (type.GetTypeInfo().IsValueType)
{
- var x = Expression.Constant(Activator.CreateInstance(type));
+ var x = Expression.Constant(Activator.CreateInstance(type));
var convert = Expression.Convert(x, typeof(object));
return convert;
}
@@ -33,7 +39,7 @@ public static Expression GetNewExpression(Type type)
#endif
var emptyObjectMethod = typeof(TypeEx).GetTypeInfo().GetMethod(nameof(TypeEx.GetEmptyObject));
var emptyObject = Expression.Call(null, emptyObjectMethod, type.ToConstant());
-
+
return emptyObject;
}
}
@@ -1,3 +1,9 @@
+// //-----------------------------------------------------------------------
+// // <copyright file="ICompiler.cs" company="Asynkron HB">
+// // Copyright (C) 2015-2016 Asynkron HB All rights reserved
+// // </copyright>
+// //-----------------------------------------------------------------------
+
using System;
using System.Reflection;
@@ -8,7 +14,7 @@ public interface ICompiler<out TDel>
int NewObject(Type type);
int Parameter<T>(string name);
int Variable<T>(string name);
- int Variable(string name,Type type);
+ int Variable(string name, Type type);
int GetVariable<T>(string name);
int Constant(object value);
int CastOrUnbox(int value, Type type);
@@ -1,3 +1,9 @@
+// //-----------------------------------------------------------------------
+// // <copyright file="IlBuilder.cs" company="Asynkron HB">
+// // Copyright (C) 2015-2016 Asynkron HB All rights reserved
+// // </copyright>
+// //-----------------------------------------------------------------------
+
using System;
using System.Collections.Generic;
using System.Linq;
@@ -54,7 +60,7 @@ public int Variable<T>(string name)
return _expressions.Count - 1;
}
- public int Variable(string name,Type type)
+ public int Variable(string name, Type type)
{
var exp = new IlVariable(Variables.Count, type, name);
_expressions.Add(exp);
@@ -1,4 +1,10 @@
-using System;
+// //-----------------------------------------------------------------------
+// // <copyright file="IlCompiler.cs" company="Asynkron HB">
+// // Copyright (C) 2015-2016 Asynkron HB All rights reserved
+// // </copyright>
+// //-----------------------------------------------------------------------
+
+using System;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
@@ -1,3 +1,9 @@
+// //-----------------------------------------------------------------------
+// // <copyright file="IlCompilerContext.cs" company="Asynkron HB">
+// // Copyright (C) 2015-2016 Asynkron HB All rights reserved
+// // </copyright>
+// //-----------------------------------------------------------------------
+
using System;
using System.Reflection;
using System.Reflection.Emit;
@@ -39,6 +45,7 @@ public class IlEmitter
{
private readonly ILGenerator _il;
private readonly StringBuilder _sb = new StringBuilder();
+
public IlEmitter(ILGenerator il)
{
_il = il;
@@ -55,10 +62,10 @@ public void Emit(OpCode opcode)
_il.Emit(opcode);
}
- public void Emit(OpCode opcode,FieldInfo field)
+ public void Emit(OpCode opcode, FieldInfo field)
{
_sb.AppendLine($"{opcode} field {field}");
- _il.Emit(opcode,field);
+ _il.Emit(opcode, field);
}
public void Emit(OpCode opcode, ConstructorInfo ctor)
@@ -1,4 +1,10 @@
-using System;
+// //-----------------------------------------------------------------------
+// // <copyright file="IlExpression.cs" company="Asynkron HB">
+// // Copyright (C) 2015-2016 Asynkron HB All rights reserved
+// // </copyright>
+// //-----------------------------------------------------------------------
+
+using System;
using System.Reflection;
using System.Reflection.Emit;
using Wire.Extensions;
@@ -33,14 +39,15 @@ public override void Emit(IlCompilerContext ctx)
public class IlRuntimeConstant : IlExpression
{
private readonly object _object;
- public int Index { get; }
public IlRuntimeConstant(object value, int index)
{
_object = value;
Index = index;
}
+ public int Index { get; }
+
public override void Emit(IlCompilerContext ctx)
{
var field = ctx.SelfType.GetFields(BindingFlagsEx.All)[Index];
@@ -75,8 +82,8 @@ public override void Emit(IlCompilerContext ctx)
public class IlWriteVariable : IlExpression
{
- private readonly IlVariable _variable;
private readonly IlExpression _value;
+ private readonly IlVariable _variable;
public IlWriteVariable(IlVariable variable, IlExpression value)
{
@@ -146,8 +153,6 @@ public override void Emit(IlCompilerContext ctx)
public class IlParameter : IlExpression
{
- public string Name { get; }
- public int ParameterIndex { get; }
private readonly Type _type;
public IlParameter(int parameterIndex, Type type, string name)
@@ -157,6 +162,9 @@ public IlParameter(int parameterIndex, Type type, string name)
_type = type;
}
+ public string Name { get; }
+ public int ParameterIndex { get; }
+
public override void Emit(IlCompilerContext ctx)
{
ctx.Il.Emit(OpCodes.Ldarg, ParameterIndex);
@@ -168,17 +176,17 @@ public override void Emit(IlCompilerContext ctx)
public class IlVariable : IlExpression
{
- public int VariableIndex { get; }
- public string Name { get; }
- public Type VarType { get; }
-
public IlVariable(int variableIndex, Type type, string name)
{
VariableIndex = variableIndex;
Name = name;
VarType = type;
}
+ public int VariableIndex { get; }
+ public string Name { get; }
+ public Type VarType { get; }
+
public override void Emit(IlCompilerContext ctx)
{
ctx.Il.Emit(OpCodes.Ldloc, VariableIndex);
@@ -190,8 +198,8 @@ public override void Emit(IlCompilerContext ctx)
public class IlCastClass : IlExpression
{
- private readonly Type _type;
private readonly IlExpression _expression;
+ private readonly Type _type;
public IlCastClass(Type type, IlExpression expression)
{
@@ -212,8 +220,8 @@ public override void Emit(IlCompilerContext ctx)
public class IlBox : IlExpression
{
- private readonly Type _type;
private readonly IlExpression _expression;
+ private readonly Type _type;
public IlBox(Type type, IlExpression expression)
{
@@ -232,8 +240,8 @@ public override void Emit(IlCompilerContext ctx)
public class IlUnbox : IlExpression
{
- private readonly Type _type;
private readonly IlExpression _expression;
+ private readonly Type _type;
public IlUnbox(Type type, IlExpression expression)
{
@@ -252,9 +260,9 @@ public override void Emit(IlCompilerContext ctx)
public class IlCall : IlExpression
{
- private readonly IlExpression _target;
- private readonly MethodInfo _method;
private readonly IlExpression[] _args;
+ private readonly MethodInfo _method;
+ private readonly IlExpression _target;
public IlCall(IlExpression target, MethodInfo method, params IlExpression[] args)
{
@@ -288,8 +296,8 @@ public override void Emit(IlCompilerContext ctx)
public class IlCallStatic : IlExpression
{
- private readonly MethodInfo _method;
private readonly IlExpression[] _args;
+ private readonly MethodInfo _method;
public IlCallStatic(MethodInfo method, params IlExpression[] args)
{
Oops, something went wrong.

0 comments on commit 6bf0b8f

Please sign in to comment.