This commit is contained in:
neuecc 2017-03-02 10:12:35 +09:00
Родитель b8676c8564
Коммит 3f67611328
16 изменённых файлов: 469 добавлений и 27 удалений

Просмотреть файл

@ -45,6 +45,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessagePackAnalyzer", "src\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessagePackAnalyzer.Vsix", "src\MessagePackAnalyzer.Vsix\MessagePackAnalyzer.Vsix.csproj", "{09B87BEB-D9A3-4EEB-B56A-ED53D27DF1A3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XamarinAndroid", "sandbox\XamarinAndroid\XamarinAndroid.csproj", "{307A14EF-C896-4024-BD80-95A55B22C2AB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -187,6 +189,24 @@ Global
{09B87BEB-D9A3-4EEB-B56A-ED53D27DF1A3}.Release|x64.Build.0 = Release|Any CPU
{09B87BEB-D9A3-4EEB-B56A-ED53D27DF1A3}.Release|x86.ActiveCfg = Release|Any CPU
{09B87BEB-D9A3-4EEB-B56A-ED53D27DF1A3}.Release|x86.Build.0 = Release|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Debug|x64.ActiveCfg = Debug|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Debug|x64.Build.0 = Debug|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Debug|x64.Deploy.0 = Debug|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Debug|x86.ActiveCfg = Debug|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Debug|x86.Build.0 = Debug|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Debug|x86.Deploy.0 = Debug|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Release|Any CPU.Build.0 = Release|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Release|Any CPU.Deploy.0 = Release|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Release|x64.ActiveCfg = Release|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Release|x64.Build.0 = Release|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Release|x64.Deploy.0 = Release|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Release|x86.ActiveCfg = Release|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Release|x86.Build.0 = Release|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Release|x86.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -203,5 +223,6 @@ Global
{E066F547-7261-4561-AEFC-E64DBFD874F8} = {86309CF6-0054-4CE3-BFD3-CA0AA7DB17BC}
{2F9A6E0C-DE95-4460-96B7-EB72BBEAEE9E} = {86309CF6-0054-4CE3-BFD3-CA0AA7DB17BC}
{09B87BEB-D9A3-4EEB-B56A-ED53D27DF1A3} = {86309CF6-0054-4CE3-BFD3-CA0AA7DB17BC}
{307A14EF-C896-4024-BD80-95A55B22C2AB} = {BF4C4202-5015-4FBD-80E6-D0F36A06F700}
EndGlobalSection
EndGlobal

110
README.md
Просмотреть файл

@ -1,36 +1,45 @@
MessagePack for C#(.NET, .NET Core, Unity)
MessagePack for C#(.NET, .NET Core, Unity, Xamarin)
===
Brainchild of [ZeroFormatter](https://github.com/neuecc/ZeroFormatter/), fastest MessagePack serializer on .NET.
Work in progress, stay tuned.
> TODO:Writing document now.
![image](https://cloud.githubusercontent.com/assets/46207/23337257/9bf22222-fc2a-11e6-888f-20d0451a526e.png)
Extremely fast [MessagePack](http://msgpack.org/) serializer for C#, x10~20 faster than MsgPack-Cli and acquires best performance compared with all the other C# serializers.
Extremely fast, x10~20 faster than MsgPack-Cli.
![image](https://cloud.githubusercontent.com/assets/46207/23487810/e263277a-ff2b-11e6-81a6-6b4ca7acd8e3.png)
![image](https://cloud.githubusercontent.com/assets/46207/23487813/e7b22e1a-ff2b-11e6-8eeb-386c6a305628.png)
MessagePack has compact binary size and full set of general purpose expression. Please see the comparison with JSON, protobuf, ZeroFormatter section. If you want to know why MessagePack C# is fastest, please see performance section.
Install
---
Beta is relased(please enable include pre-release package).
The library provides in NuGet except for Unity.
Standard library for .NET, .NET Core
Standard library for .NET, .NET Core, Xamarin.
```
Install-Package MessagePack -Pre
Install-Package MessagePack
```
for Unity, download from releases page(not yet).
Extension Packages(info is see detail section).
Visual Studio Analyzer to help object definition
```
Install-Package MessagePack.ImmutableCollection -Pre
Install-Package MessagePack.ReactiveProperty -Pre
Install-Package MessagePack.Unity -Pre
Install-Package MessagePackAnalyzer
```
Extension Packages(info is see extension section).
```
Install-Package MessagePack.ImmutableCollection
Install-Package MessagePack.ReactiveProperty
Install-Package MessagePack.Unity
```
for Unity, download from [releases](https://github.com/neuecc/MessagePack-CSharp/releases) page, providing `.unitypackage`. Unity IL2CPP or Xamarin AOT Environment, check the pre-code generation section.
Quick Start
---
Define class and mark as `[MessagePackObject]` and public properties mark `[Key]`, call `MessagePackSerializer.Serialize<T>/Deserialize<T>`.
Define class and mark as `[MessagePackObject]` and public members(property or field) mark `[Key]`, call `MessagePackSerializer.Serialize<T>/Deserialize<T>`.
```csharp
// mark MessagePackObjectAttribute
@ -62,26 +71,89 @@ class Program
LastName = "huga",
};
// call Serialize/Deserialize, that's all.
// call Serialize/Deserialize, that's all.
var bytes = MessagePackSerializer.Serialize(mc);
var mc2 = MessagePackSerializer.Deserialize<MyClass>(bytes);
}
}
```
Union
By default the attribute is required. Optionally it can be unnecessary, see Object Serialization Format section and Formatter Resolver section for details.
Analyzer
---
TODO:
Built-in support types
---
TODO:
Object Serialization Format
---
TODO:
Union
---
TODO:
Note:Versioning....
Performance
---
TODO:
FormatterResolver
---
TODO:
MessagePackSerializer API
---
Extensions
---
TODO:
Pre Code Generation(mpc.exe)
---
Build
RPC
---
TODO:
How to Build
---
Open `MessagePack.sln` on Visual Studio 2017.
Unity Project is using symbolic link. At first, run `make_unity_symlink.bat` so linked under Unity project. You can open `src\MessagePack.UnityClient` on Unity Editor.
CodeGenerator(`mpc.exe`) is merged single exe to many dll by [LibZ](https://github.com/MiloszKrajewski/LibZ). run `build_libz.bat`, you can combine it.
Author Info
---
Yoshifumi Kawai(a.k.a. neuecc) is a software developer in Japan.
He is the Director/CTO at Grani, Inc.
Grani is a top social game developer in Japan.
He is awarding Microsoft MVP for Visual C# since 2011.
He is known as the creator of [UniRx](http://github.com/neuecc/UniRx/)(Reactive Extensions for Unity)
Blog: https://medium.com/@neuecc (English)
Blog: http://neue.cc/ (Japanese)
Twitter: https://twitter.com/neuecc (Japanese)
License
---
This library is under the MIT License.

Двоичные данные
graph.xlsx Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -197,6 +197,8 @@ namespace Sandbox
static void Benchmark<T>(T target)
{
const int Iteration = 10000;
var msgpack = MsgPack.Serialization.SerializationContext.Default;
msgpack.GetSerializer<T>().PackSingleObject(target);
MessagePack.MessagePackSerializer.Serialize(target);
@ -213,7 +215,7 @@ namespace Sandbox
byte[] data2 = null;
using (new Measure("MsgPack-Cli"))
{
for (int i = 0; i < 100000; i++)
for (int i = 0; i < Iteration; i++)
{
data = msgpack.GetSerializer<T>().PackSingleObject(target);
}
@ -221,21 +223,21 @@ namespace Sandbox
using (new Measure("MessagePack-CSharp"))
{
for (int i = 0; i < 100000; i++)
for (int i = 0; i < Iteration; i++)
{
data0 = MessagePack.MessagePackSerializer.Serialize(target);
}
}
using (new Measure("ZeroFormatter"))
{
for (int i = 0; i < 100000; i++)
for (int i = 0; i < Iteration; i++)
{
data1 = ZeroFormatter.ZeroFormatterSerializer.Serialize(target);
}
}
using (new Measure("protobuf-net"))
{
for (int i = 0; i < 100000; i++)
for (int i = 0; i < Iteration; i++)
{
using (var ms = new MemoryStream())
{
@ -260,7 +262,7 @@ namespace Sandbox
using (new Measure("MsgPack-Cli"))
{
for (int i = 0; i < 100000; i++)
for (int i = 0; i < Iteration; i++)
{
msgpack.GetSerializer<T>().UnpackSingleObject(data);
}
@ -268,7 +270,7 @@ namespace Sandbox
using (new Measure("MessagePack-CSharp"))
{
for (int i = 0; i < 100000; i++)
for (int i = 0; i < Iteration; i++)
{
MessagePack.MessagePackSerializer.Deserialize<T>(data0);
}
@ -276,7 +278,7 @@ namespace Sandbox
using (new Measure("ZeroFormatter"))
{
for (int i = 0; i < 100000; i++)
for (int i = 0; i < Iteration; i++)
{
ZeroFormatterSerializer.Deserialize<T>(data1);
}
@ -284,7 +286,7 @@ namespace Sandbox
using (new Measure("protobuf-net"))
{
for (int i = 0; i < 100000; i++)
for (int i = 0; i < Iteration; i++)
{
using (var ms = new MemoryStream(data2))
{

Просмотреть файл

@ -0,0 +1,19 @@
Any raw assets you want to be deployed with your application can be placed in
this directory (and child directories) and given a Build Action of "AndroidAsset".
These files will be deployed with you package and will be accessible using Android's
AssetManager, like this:
public class ReadAsset : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
InputStream input = Assets.Open ("my_asset.txt");
}
}
Additionally, some Android functions will automatically load asset files:
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");

Просмотреть файл

@ -0,0 +1,4 @@
<GettingStarted>
<LocalContent>GS\Android\CS\AndroidApp\GettingStarted.html</LocalContent>
<EmbeddedNavigation>false</EmbeddedNavigation>
</GettingStarted>

Просмотреть файл

@ -0,0 +1,34 @@
using Android.App;
using Android.Widget;
using Android.OS;
using MessagePack;
namespace XamarinAndroid
{
[MessagePackObject]
public class MyClass
{
[Key(0)]
public int MyProperty { get; set; }
}
[Activity(Label = "XamarinAndroid", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
var hoge = MessagePackSerializer.Serialize(new MyClass());
var huga = MessagePackSerializer.Deserialize<MyClass>(hoge);
System.Console.WriteLine(huga.MyProperty);
base.OnCreate(bundle);
// Set our view from the "main" layout resource
// SetContentView (Resource.Layout.Main);
}
}
}

Просмотреть файл

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="XamarinAndroid.XamarinAndroid" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="16" />
<application android:label="XamarinAndroid"></application>
</manifest>

Просмотреть файл

@ -0,0 +1,30 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Android.App;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("XamarinAndroid")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("XamarinAndroid")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Просмотреть файл

@ -0,0 +1,44 @@
Images, layout descriptions, binary blobs and string dictionaries can be included
in your application as resource files. Various Android APIs are designed to
operate on the resource IDs instead of dealing with images, strings or binary blobs
directly.
For example, a sample Android app that contains a user interface layout (main.axml),
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
would keep its resources in the "Resources" directory of the application:
Resources/
drawable/
icon.png
layout/
main.axml
values/
strings.xml
In order to get the build system to recognize Android resources, set the build action to
"AndroidResource". The native Android APIs do not operate directly with filenames, but
instead operate on resource IDs. When you compile an Android application that uses resources,
the build system will package the resources for distribution and generate a class called "R"
(this is an Android convention) that contains the tokens for each one of the resources
included. For example, for the above Resources layout, this is what the R class would expose:
public class R {
public class drawable {
public const int icon = 0x123;
}
public class layout {
public const int main = 0x456;
}
public class strings {
public const int first_string = 0xabc;
public const int second_string = 0xbcd;
}
}
You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main
to reference the layout/main.axml file, or R.strings.first_string to reference the first
string in the dictionary file values/strings.xml.

96
sandbox/XamarinAndroid/Resources/Resource.Designer.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,96 @@
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
// このコードはツールによって生成されました。
// ランタイム バージョン:4.0.30319.42000
//
// このファイルへの変更は、以下の状況下で不正な動作の原因になったり、
// コードが再生成されるときに損失したりします。
// </auto-generated>
//------------------------------------------------------------------------------
[assembly: global::Android.Runtime.ResourceDesignerAttribute("XamarinAndroid.Resource", IsApplication=true)]
namespace XamarinAndroid
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]
public partial class Resource
{
static Resource()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
public static void UpdateIdValues()
{
}
public partial class Attribute
{
static Attribute()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Attribute()
{
}
}
public partial class Drawable
{
// aapt resource value: 0x7f020000
public const int Icon = 2130837504;
static Drawable()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Drawable()
{
}
}
public partial class Layout
{
// aapt resource value: 0x7f030000
public const int Main = 2130903040;
static Layout()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Layout()
{
}
}
public partial class String
{
// aapt resource value: 0x7f040001
public const int ApplicationName = 2130968577;
// aapt resource value: 0x7f040000
public const int Hello = 2130968576;
static String()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private String()
{
}
}
}
}
#pragma warning restore 1591

Двоичные данные
sandbox/XamarinAndroid/Resources/drawable/Icon.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 4.0 KiB

Просмотреть файл

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</LinearLayout>

Просмотреть файл

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="Hello">Hello World, Click Me!</string>
<string name="ApplicationName">XamarinAndroid</string>
</resources>

Просмотреть файл

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{307A14EF-C896-4024-BD80-95A55B22C2AB}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>XamarinAndroid</RootNamespace>
<AssemblyName>XamarinAndroid</AssemblyName>
<FileAlignment>512</FileAlignment>
<AndroidApplication>True</AndroidApplication>
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>True</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>
<AndroidLinkMode>None</AndroidLinkMode>
<EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>PdbOnly</DebugType>
<DebugSymbols>True</DebugSymbols>
<Optimize>True</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
</PropertyGroup>
<ItemGroup>
<Reference Include="MessagePack, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\MessagePack.0.4.2\lib\netstandard1.4\MessagePack.dll</HintPath>
</Reference>
<Reference Include="Mono.Android" />
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="GettingStarted.Xamarin" />
<None Include="packages.config" />
<None Include="Resources\AboutResources.txt" />
<None Include="Assets\AboutAssets.txt" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\Main.axml">
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\values\Strings.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\Icon.png" />
</ItemGroup>
<ItemGroup>
<None Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<!-- 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">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Просмотреть файл

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MessagePack" version="0.4.2" targetFramework="monoandroid60" />
<package id="System.Reflection.Emit" version="4.3.0" targetFramework="monoandroid60" />
<package id="System.Threading.Tasks.Extensions" version="4.3.0" targetFramework="monoandroid60" />
<package id="System.ValueTuple" version="4.3.0" targetFramework="monoandroid60" />
</packages>