зеркало из https://github.com/akkadotnet/Hyperion.git
Added unsigned types
This commit is contained in:
Родитель
8849a974c6
Коммит
ed5d088b14
|
@ -1,5 +1,7 @@
|
|||
namespace Wire.FSharpTestTypes
|
||||
|
||||
open Akka.Actor
|
||||
|
||||
type DU1 =
|
||||
| A of int
|
||||
| B of string * int
|
||||
|
@ -8,5 +10,33 @@ and DU2 =
|
|||
| D of string
|
||||
| E of option<DU1>
|
||||
|
||||
type HubType =
|
||||
| Task of unit
|
||||
| Chat of unit
|
||||
|
||||
type Connection =
|
||||
{ username : string
|
||||
id : string
|
||||
hubType : HubType
|
||||
signalrAref : IActorRef }
|
||||
|
||||
[<CustomEquality;CustomComparison>]
|
||||
type User =
|
||||
{ name : string
|
||||
aref : string option
|
||||
connections : string}
|
||||
|
||||
override x.Equals(yobj) =
|
||||
match yobj with
|
||||
| :? User as y -> (x.name = y.name)
|
||||
| _ -> false
|
||||
|
||||
override x.GetHashCode() = hash x.name
|
||||
interface System.IComparable with
|
||||
member x.CompareTo yobj =
|
||||
match yobj with
|
||||
| :? User as y -> compare x.name y.name
|
||||
| _ -> invalidArg "yobj" "cannot compare values of different types"
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -33,20 +33,6 @@
|
|||
<WarningLevel>3</WarningLevel>
|
||||
<DocumentationFile>bin\Release\Wire.FSharpTestTypes.XML</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Numerics" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AssemblyInfo.fs" />
|
||||
<Compile Include="Library1.fs" />
|
||||
<None Include="Script.fsx" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
|
@ -63,6 +49,29 @@
|
|||
</Otherwise>
|
||||
</Choose>
|
||||
<Import Project="$(FSharpTargetsPath)" />
|
||||
<ItemGroup>
|
||||
<Compile Include="AssemblyInfo.fs" />
|
||||
<Compile Include="Library1.fs" />
|
||||
<None Include="Script.fsx" />
|
||||
<Content Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Akka">
|
||||
<HintPath>..\packages\Akka.1.0.4\lib\net45\Akka.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Numerics" />
|
||||
</ItemGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Akka" version="1.0.4" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
|
||||
</packages>
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.FSharp.Core;
|
||||
using Akka.Actor;
|
||||
using Microsoft.FSharp.Core;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Wire.FSharpTestTypes;
|
||||
|
||||
|
@ -46,5 +47,26 @@ namespace Wire.Tests
|
|||
var actual = Deserialize<object>();
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
public class FooActor : UntypedActor
|
||||
{
|
||||
protected override void OnReceive(object message)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CanSerializeUser()
|
||||
{
|
||||
var expected = new User("foo", new FSharpOption<string>(null), "hello");
|
||||
Serialize(expected);
|
||||
Reset();
|
||||
var actual = Deserialize<User>();
|
||||
// Assert.AreEqual(expected, actual);
|
||||
Assert.AreEqual(expected.aref, actual.aref);
|
||||
Assert.AreEqual(expected.name, actual.name);
|
||||
Assert.AreEqual(expected.connections, actual.connections);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,15 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Akka, Version=1.0.4.12, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Akka.1.0.4\lib\net45\Akka.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
|
@ -72,6 +80,9 @@
|
|||
<Name>Wire</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||
<ItemGroup>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Akka" version="1.0.4" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
|
||||
</packages>
|
|
@ -13,6 +13,11 @@ namespace Wire
|
|||
private static readonly Type Int32Type = typeof (int);
|
||||
private static readonly Type Int64Type = typeof (long);
|
||||
private static readonly Type Int16Type = typeof (short);
|
||||
|
||||
private static readonly Type UInt32Type = typeof(uint);
|
||||
private static readonly Type UInt64Type = typeof(ulong);
|
||||
private static readonly Type UInt16Type = typeof(ushort);
|
||||
|
||||
private static readonly Type ByteType = typeof (byte);
|
||||
private static readonly Type BoolType = typeof (bool);
|
||||
private static readonly Type DateTimeType = typeof (DateTime);
|
||||
|
@ -49,6 +54,9 @@ namespace Wire
|
|||
return type == Int32Type ||
|
||||
type == Int64Type ||
|
||||
type == Int16Type ||
|
||||
type == UInt32Type ||
|
||||
type == UInt64Type ||
|
||||
type == UInt16Type ||
|
||||
type == DateTimeType ||
|
||||
type == BoolType ||
|
||||
type == StringType ||
|
||||
|
@ -263,7 +271,7 @@ namespace Wire
|
|||
}
|
||||
|
||||
public ValueSerializer GetDeserializerByManifest(Stream stream, SerializerSession session)
|
||||
{
|
||||
{
|
||||
var first = stream.ReadByte();
|
||||
switch (first)
|
||||
{
|
||||
|
@ -296,8 +304,14 @@ namespace Wire
|
|||
return DecimalSerializer.Instance;
|
||||
case CharSerializer.Manifest:
|
||||
return CharSerializer.Instance;
|
||||
case TypeSerializer.Manifest:
|
||||
case TypeSerializer.Manifest:
|
||||
return TypeSerializer.Instance;
|
||||
case UInt16Serializer.Manifest:
|
||||
return UInt16Serializer.Instance;
|
||||
case UInt32Serializer.Manifest:
|
||||
return UInt32Serializer.Instance;
|
||||
case UInt64Serializer.Manifest:
|
||||
return UInt64Serializer.Instance;
|
||||
case ObjectReferenceSerializer.Manifest:
|
||||
return ObjectReferenceSerializer.Instance;
|
||||
case ConsistentArraySerializer.Manifest:
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Wire.Converters;
|
||||
|
||||
|
@ -37,29 +36,4 @@ namespace Wire
|
|||
PreserveObjectReferences = preserveObjectReferences;
|
||||
}
|
||||
}
|
||||
|
||||
public class Surrogate
|
||||
{
|
||||
public Type From { get; protected set; }
|
||||
public Type To { get; protected set; }
|
||||
public Func<object, object> FromSurrogate { get; protected set; }
|
||||
public Func<object, object> ToSurrogate { get; protected set; }
|
||||
|
||||
public static Surrogate Create<TSource, TSurrogate>(Func<TSource, TSurrogate> toSurrogate,
|
||||
Func<TSurrogate, TSource> fromSurrogate)
|
||||
{
|
||||
return new Surrogate<TSource, TSurrogate>(toSurrogate, fromSurrogate);
|
||||
}
|
||||
}
|
||||
|
||||
public class Surrogate<TSource, TSurrogate> : Surrogate
|
||||
{
|
||||
public Surrogate(Func<TSource, TSurrogate> toSurrogate, Func<TSurrogate, TSource> fromSurrogate)
|
||||
{
|
||||
ToSurrogate = from => toSurrogate((TSource) from);
|
||||
FromSurrogate = to => fromSurrogate((TSurrogate) to);
|
||||
From = typeof (TSource);
|
||||
To = typeof (TSurrogate);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ namespace Wire
|
|||
{
|
||||
public class SerializerSession
|
||||
{
|
||||
private byte[] _buffer;
|
||||
private readonly byte[] _buffer;
|
||||
private readonly Dictionary<int, object> _objectById;
|
||||
private readonly Dictionary<object, int> _objects;
|
||||
public readonly Serializer Serializer;
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
|
||||
namespace Wire
|
||||
{
|
||||
public class Surrogate<TSource, TSurrogate> : Surrogate
|
||||
{
|
||||
public Surrogate(Func<TSource, TSurrogate> toSurrogate, Func<TSurrogate, TSource> fromSurrogate)
|
||||
{
|
||||
ToSurrogate = from => toSurrogate((TSource) from);
|
||||
FromSurrogate = to => fromSurrogate((TSurrogate) to);
|
||||
From = typeof (TSource);
|
||||
To = typeof (TSurrogate);
|
||||
}
|
||||
}
|
||||
|
||||
public class Surrogate
|
||||
{
|
||||
public Type From { get; protected set; }
|
||||
public Type To { get; protected set; }
|
||||
public Func<object, object> FromSurrogate { get; protected set; }
|
||||
public Func<object, object> ToSurrogate { get; protected set; }
|
||||
|
||||
public static Surrogate Create<TSource, TSurrogate>(Func<TSource, TSurrogate> toSurrogate,
|
||||
Func<TSurrogate, TSource> fromSurrogate)
|
||||
{
|
||||
return new Surrogate<TSource, TSurrogate>(toSurrogate, fromSurrogate);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Wire.ValueSerializers
|
||||
{
|
||||
public class UInt16Serializer : ValueSerializer
|
||||
{
|
||||
public static readonly UInt16Serializer Instance = new UInt16Serializer();
|
||||
public const byte Manifest = 17;
|
||||
|
||||
public override void WriteManifest(Stream stream, Type type, SerializerSession session)
|
||||
{
|
||||
stream.WriteByte(Manifest);
|
||||
}
|
||||
|
||||
public override void WriteValue(Stream stream, object value, SerializerSession session)
|
||||
{
|
||||
var bytes = BitConverter.GetBytes((UInt16)value);
|
||||
stream.Write(bytes);
|
||||
}
|
||||
|
||||
public override object ReadValue(Stream stream, SerializerSession session)
|
||||
{
|
||||
var size = sizeof(UInt16);
|
||||
var buffer = session.GetBuffer(size);
|
||||
stream.Read(buffer, 0, size);
|
||||
return BitConverter.ToUInt16(buffer, 0);
|
||||
}
|
||||
|
||||
public override Type GetElementType()
|
||||
{
|
||||
return typeof(UInt16);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Wire.ValueSerializers
|
||||
{
|
||||
public class UInt32Serializer : ValueSerializer
|
||||
{
|
||||
public static readonly UInt32Serializer Instance = new UInt32Serializer();
|
||||
public const byte Manifest = 18;
|
||||
|
||||
public override void WriteManifest(Stream stream, Type type, SerializerSession session)
|
||||
{
|
||||
stream.WriteByte(Manifest);
|
||||
}
|
||||
|
||||
public override void WriteValue(Stream stream, object value, SerializerSession session)
|
||||
{
|
||||
var bytes = BitConverter.GetBytes((UInt32)value);
|
||||
stream.Write(bytes);
|
||||
}
|
||||
|
||||
public override object ReadValue(Stream stream, SerializerSession session)
|
||||
{
|
||||
var size = sizeof(UInt32);
|
||||
var buffer = session.GetBuffer(size);
|
||||
stream.Read(buffer, 0, size);
|
||||
return BitConverter.ToUInt32(buffer, 0);
|
||||
}
|
||||
|
||||
public override Type GetElementType()
|
||||
{
|
||||
return typeof(UInt32);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Wire.ValueSerializers
|
||||
{
|
||||
public class UInt64Serializer : ValueSerializer
|
||||
{
|
||||
public static readonly UInt64Serializer Instance = new UInt64Serializer();
|
||||
public const byte Manifest = 19;
|
||||
|
||||
public override void WriteManifest(Stream stream, Type type, SerializerSession session)
|
||||
{
|
||||
stream.WriteByte(Manifest);
|
||||
}
|
||||
|
||||
public override void WriteValue(Stream stream, object value, SerializerSession session)
|
||||
{
|
||||
var bytes = BitConverter.GetBytes((UInt64)value);
|
||||
stream.Write(bytes);
|
||||
}
|
||||
|
||||
public override object ReadValue(Stream stream, SerializerSession session)
|
||||
{
|
||||
var size = sizeof(UInt64);
|
||||
var buffer = session.GetBuffer(size);
|
||||
stream.Read(buffer, 0, size);
|
||||
return BitConverter.ToUInt64(buffer, 0);
|
||||
}
|
||||
|
||||
public override Type GetElementType()
|
||||
{
|
||||
return typeof(UInt64);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -51,6 +51,7 @@
|
|||
<Compile Include="Converters\ValueSerializerFactory.cs" />
|
||||
<Compile Include="SerializerOptions.cs" />
|
||||
<Compile Include="StreamExtensions.cs" />
|
||||
<Compile Include="Surrogate.cs" />
|
||||
<Compile Include="ValueSerializers\ArraySerializer.cs" />
|
||||
<Compile Include="ValueSerializers\BoolSerializer.cs" />
|
||||
<Compile Include="ValueSerializers\ByteArraySerializer.cs" />
|
||||
|
@ -75,6 +76,9 @@
|
|||
<Compile Include="ValueSerializers\StringSerializer.cs" />
|
||||
<Compile Include="ValueSerializers\ToSurrogateSerializer.cs" />
|
||||
<Compile Include="ValueSerializers\TypeSerializer.cs" />
|
||||
<Compile Include="ValueSerializers\UInt16Serializer.cs" />
|
||||
<Compile Include="ValueSerializers\UInt32Serializer.cs" />
|
||||
<Compile Include="ValueSerializers\UInt64Serializer.cs" />
|
||||
<Compile Include="ValueSerializers\ValueSerializer.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
Загрузка…
Ссылка в новой задаче