File tree 5 files changed +146
-3
lines changed
5 files changed +146
-3
lines changed Original file line number Diff line number Diff line change
1
+ using System . Collections . Generic ;
2
+ using BinarySerialization ;
3
+
4
+ namespace BinarySerializer . Console
5
+ {
6
+ public class Beer
7
+ {
8
+ [ SerializeAs ( SerializedType . LengthPrefixedString ) ]
9
+ [ FieldOrder ( 0 ) ]
10
+ public string Brand ;
11
+
12
+ [ FieldOrder ( 1 ) ]
13
+ public byte SortCount ;
14
+
15
+ [ FieldOrder ( 2 ) ]
16
+ [ FieldCount ( "SortCount" ) ]
17
+ public List < SortContainer > Sort ;
18
+
19
+ [ FieldOrder ( 3 ) ]
20
+ public float Alcohol ;
21
+
22
+ [ SerializeAs ( SerializedType . LengthPrefixedString ) ]
23
+ [ FieldOrder ( 4 ) ]
24
+ public string Brewery ;
25
+ }
26
+
27
+ public class SortContainer
28
+ {
29
+ [ FieldOrder ( 0 ) ]
30
+ public byte NameLength ;
31
+
32
+ [ FieldOrder ( 1 ) ]
33
+ [ FieldLength ( "NameLength" ) ]
34
+ public string Name ;
35
+ }
36
+ }
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" utf-8" ?>
2
+ <Project ToolsVersion =" 14.0" DefaultTargets =" Build" xmlns =" http://schemas.microsoft.com/developer/msbuild/2003" >
3
+ <PropertyGroup >
4
+ <VisualStudioVersion Condition =" '$(VisualStudioVersion)' == ''" >14.0</VisualStudioVersion >
5
+ <VSToolsPath Condition =" '$(VSToolsPath)' == ''" >$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath >
6
+ </PropertyGroup >
7
+
8
+ <Import Project =" $(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition =" '$(VSToolsPath)' != ''" />
9
+ <PropertyGroup Label =" Globals" >
10
+ <ProjectGuid >9088377d-4bf5-4521-870a-a417a6c804ca</ProjectGuid >
11
+ <RootNamespace >BinarySerializer.Console</RootNamespace >
12
+ <BaseIntermediateOutputPath Condition =" '$(BaseIntermediateOutputPath)'=='' " >..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath >
13
+ <OutputPath Condition =" '$(OutputPath)'=='' " >..\artifacts\bin\$(MSBuildProjectName)\</OutputPath >
14
+ </PropertyGroup >
15
+
16
+ <PropertyGroup >
17
+ <SchemaVersion >2.0</SchemaVersion >
18
+ </PropertyGroup >
19
+ <Import Project =" $(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition =" '$(VSToolsPath)' != ''" />
20
+ </Project >
Original file line number Diff line number Diff line change
1
+ using System . Collections . Generic ;
2
+ using System . Diagnostics ;
3
+ using System . IO ;
4
+
5
+ namespace BinarySerializer . Console
6
+ {
7
+ public class Program
8
+ {
9
+ public static void Main ( string [ ] args )
10
+ {
11
+ var beer = new Beer
12
+ {
13
+ Alcohol = 6 ,
14
+
15
+ Brand = "Brand" ,
16
+ Sort = new List < SortContainer >
17
+ {
18
+ new SortContainer { Name = "some sort of beer" }
19
+ } ,
20
+ Brewery = "Brasserie Grain d'Orge"
21
+ } ;
22
+
23
+ DoBS ( beer , 100000 ) ;
24
+ }
25
+
26
+ private static void DoBS < T > ( T obj , int iterations )
27
+ {
28
+ var ser = new BinarySerialization . BinarySerializer ( ) ;
29
+
30
+ var stopwatch = new Stopwatch ( ) ;
31
+ using ( var ms = new MemoryStream ( ) )
32
+ {
33
+ stopwatch . Start ( ) ;
34
+ for ( int i = 0 ; i < iterations ; i ++ )
35
+ {
36
+ ser . Serialize ( ms , obj ) ;
37
+ }
38
+ stopwatch . Stop ( ) ;
39
+ System . Console . WriteLine ( "BS SER: {0}" , stopwatch . Elapsed ) ;
40
+ stopwatch . Reset ( ) ;
41
+ }
42
+
43
+ var dataStream = new MemoryStream ( ) ;
44
+ ser . Serialize ( dataStream , obj ) ;
45
+ byte [ ] data = dataStream . ToArray ( ) ;
46
+
47
+ using ( var ms = new MemoryStream ( data ) )
48
+ {
49
+ stopwatch . Start ( ) ;
50
+ for ( int i = 0 ; i < iterations ; i ++ )
51
+ {
52
+ ser . Deserialize < T > ( ms ) ;
53
+ ms . Position = 0 ;
54
+ }
55
+ stopwatch . Stop ( ) ;
56
+ System . Console . WriteLine ( "BS DESER: {0}" , stopwatch . Elapsed ) ;
57
+ stopwatch . Reset ( ) ;
58
+ }
59
+ }
60
+ }
61
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "version" : " 1.0.0-*" ,
3
+ "description" : " BinarySerializer.Console Console Application" ,
4
+ "authors" : [ " Jeff" ],
5
+ "tags" : [ " " ],
6
+ "projectUrl" : " " ,
7
+ "licenseUrl" : " " ,
8
+
9
+ "compilationOptions" : {
10
+ "emitEntryPoint" : true
11
+ },
12
+
13
+ "dependencies" : {
14
+ "BinarySerializer" : " 5.0-beta2"
15
+ },
16
+
17
+ "frameworks" : {
18
+ "dotnet" : {
19
+ "dependencies" : {
20
+ "System.Console" : " 4.0.0-rc3-24008-00"
21
+ }
22
+ }
23
+ }
24
+ }
Original file line number Diff line number Diff line change 4
4
<Description >A declarative serialization framework for controlling formatting of data at the byte level.</Description >
5
5
<AssemblyName >BinarySerializer</AssemblyName >
6
6
<PackageTags >Serialization;Serializer;Binary;Format;Protocol</PackageTags >
7
- <PackageReleaseNotes >Updated package to target .NET Platform Standard 1.3</PackageReleaseNotes >
8
- <PackageProjectUrl >https://github.com/Mephistofeles/BinarySerializer.git </PackageProjectUrl >
7
+ <PackageReleaseNotes >Updated package to target .NET Standard 1.3</PackageReleaseNotes >
8
+ <PackageProjectUrl >binaryserializer.net </PackageProjectUrl >
9
9
<PackageLicenseUrl >http://www.opensource.org/licenses/mit-license.php</PackageLicenseUrl >
10
10
<RepositoryType >git</RepositoryType >
11
- <RepositoryUrl >https://github.com/Mephistofeles/BinarySerializer.git </RepositoryUrl >
11
+ <RepositoryUrl >binaryserializer.net </RepositoryUrl >
12
12
<AssemblyVersion >7.0.0.0</AssemblyVersion >
13
13
<FileVersion >7.0.0.0</FileVersion >
14
14
<Version >7.0.0</Version >
15
15
<GeneratePackageOnBuild >True</GeneratePackageOnBuild >
16
+ <Authors >Jeff Haynes</Authors >
17
+ <Company />
16
18
</PropertyGroup >
17
19
<ItemGroup >
18
20
<PackageReference Include =" System.Collections" Version =" 4.3.0" />
You can’t perform that action at this time.
0 commit comments