Skip to content

Commit b8592bf

Browse files
committed
added README.md and project refactoring
1 parent 0f790b1 commit b8592bf

7 files changed

Lines changed: 127 additions & 25 deletions

File tree

README.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
The fastest and most compact text-based serializer for .NET -
2+
more info on its JSV Format is on the [introductory blog post](http://www.servicestack.net/mythz_blog/?p=176).
3+
4+
5+
# Fast new text-serialization format optimized for serializing C# POCO types
6+
7+
Included in the Service Stack libraries is *Type Serializer*, a fast, light-weight compact Text Serializer which can be used to serialize any .NET data type including your own custom POCO's and DataContract's.
8+
9+
Out of the box .NET provides a fairly quick but verbose Xml DataContractSerializer or a slightly more compact but slower JsonDataContractSerializer.
10+
Both of these options are fragile and likely to break with any significant schema changes.
11+
TypeSerializer addresses these shortcomings by being both smaller and significantly faster than the most popular options.
12+
It's also more resilient, e.g. a strongly-typed POCO object can be deserialized back into a loosely-typed string Dictionary and vice-versa.
13+
14+
With that in mind, TypeSerializer's main features are:
15+
* Fastest and most compact text-serializer for .NET
16+
* Human readable and writeable, self-describing text format
17+
* Non-invasive and configuration-free
18+
* Resilient to schema changes
19+
* Serializes / De-serializes any .NET data type (by convention)
20+
* Supports custom, compact serialization of structs by overriding `ToString()` and `static T Parse(string)` methods
21+
* Can serialize inherited, interface or 'late-bound objects' data types
22+
* Respects opt-in DataMember custom serialization for DataContract dto types.
23+
24+
These characteristics make it ideal for use anywhere you need to store or transport .NET data-types, e.g. for text blobs in a ORM, data in and out of a key-value store or as the text-protocol in .NET to .NET web services.
25+
26+
As such, it's utilized within ServiceStack's other components:
27+
* OrmLite - to store complex types on table models as text blobs in a database field and
28+
* [ServiceStack.Redis](https://github.com/mythz/ServiceStack.Redis) - to store rich POCO data types into the very fast [redis](http://code.google.com/p/redis) instances.
29+
30+
# Download
31+
`TypeSerializer` is included with [ServiceStack.zip](https://github.com/downloads/mythz/ServiceStack/ServiceStack.zip)
32+
or available to download separately in a standalone [ServiceStack.Text.zip](https://github.com/downloads/mythz/ServiceStack.Text/ServiceStack.Text.zip).
33+
34+
# Simple API
35+
36+
Like most of the interfaces in Service Stack, the API is simple and descriptive. In most cases these are the only methods that you would commonly use:
37+
38+
string TypeSerializer.SerializeToString<T>(T value);
39+
void TypeSerializer.SerializeToWriter<T>(T value, TextWriter writer);
40+
41+
T TypeSerializer.DeserializeFromString<T>(string value);
42+
T TypeSerializer.DeserializeFromReader<T>(TextReader reader);
43+
44+
Where *T* can be any .NET POCO type. That’s all there is - the API was intentionally left simple :)
45+
46+
You may also be interested in the very useful [T.Dump() extension method](http://www.servicestack.net/mythz_blog/?p=202) for recursively viewing the contents of any C# POCO Type.
47+
48+
----
49+
50+
# Performance
51+
Type Serializer is actually the fastest and most compact *text serializer* available for .NET.
52+
Out of all the serializers benchmarked, it is the only one to remain competitive with [http://code.google.com/p/protobuf-net/ protobuf-net]'s very fast implementation of [http://code.google.com/apis/protocolbuffers/ Protocol Buffers] - google's high-speed binary protocol.
53+
54+
Below is a series of benchmarks serialize the different tables in the [http://code.google.com/p/servicestack/source/browse/trunk/Common/Northwind.Benchmarks/Northwind.Common/DataModel/NorthwindData.cs Northwind database] (3202 records) with the most popular serializers available for .NET:
55+
56+
### Combined results for serializing / deserialzing a single row of each table in the Northwind database 1,000,000 times
57+
_[view the detailed benchmarks](http://www.servicestack.net/benchmarks/NorthwindDatabaseRowsSerialization.1000000-times.2010-02-06.html)_
58+
59+
|| Serializer || Size || Peformance ||
60+
|| Microsoft DataContractSerializer || 4.68x || 6.72x ||
61+
|| Microsoft JsonDataContractSerializer|| 2.24x || 10.18x ||
62+
|| Microsoft BinaryFormatter || 5.62x || 9.06x ||
63+
|| NewtonSoft.Json || 2.30x || 8.15x ||
64+
|| ProtoBuf.net || 1x || 1x ||
65+
|| ServiceStack TypeSerializer || 1.78x || 1.92x ||
66+
67+
_number of times larger in size and slower in performance than the best - lower is better_
68+
69+
Microsoft's JavaScriptSerializer was also benchmarked but excluded as it was up to 280x times slower - basically don't use it, ever.
70+
71+
72+
# JSV Text Format (JSON + CSV)
73+
74+
Type Serializer uses a hybrid CSV-style escaping + JavaScript-like text-based format that is optimized for both size and speed. I'm naming this JSV-format (i.e. JSON + CSV)
75+
76+
In many ways it is similar to JavaScript, e.g. any List, Array, Collection of ints, longs, etc are stored in exactly the same way, i.e:
77+
[1,2,3,4,5]
78+
79+
Any IDictionary is serialized like JavaScript, i.e:
80+
{A:1,B:2,C:3,D:4}
81+
82+
Which also happens to be the same as C# POCO class with the values
83+
84+
`new MyClass { A=1, B=2, C=3, D=4 }`
85+
86+
{A:1,B:2,C:3,D:4}
87+
88+
JSV is *white-space significant*, which means normal string values can be serialized without quotes, e.g:
89+
90+
`new MyClass { Foo="Bar", Greet="Hello World!"}` is serialized as:
91+
92+
{Foo:Bar,Greet:Hello World!}
93+
94+
95+
### CSV escaping
96+
97+
Any string with any of the following characters: `[]{},"`
98+
is escaped using CSV-style escaping where the value is wrapped in double quotes, e.g:
99+
100+
`new MyClass { Name = "Me, Junior" }` is serialized as:
101+
102+
{Name:"Me, Junior"}
103+
104+
A value with a double-quote is escaped with another double quote e.g:
105+
106+
`new MyClass { Size = "2\" x 1\"" }` is serialized as:
107+
108+
{Size:"2"" x 1"""}
109+
110+
111+
## Rich support for resilience and schema versioning
112+
To better illustrate the resilience of `TypeSerializer` and the JSV Format check out a real world example of it when it's used to [Painlessly migrate between old and new types in Redis](http://code.google.com/p/servicestack/wiki/MigrationsUsingSchemalessNoSql).
113+
114+
Support for dynamic payloads and late-bound objects is explained in the post [Versatility of JSV Late-bound objects](http://www.servicestack.net/mythz_blog/?p=314).

README.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

build/build.bat

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
REM SET BUILD=Debug
3+
SET BUILD=Release
4+
5+
COPY ..\src\ServiceStack.Text\bin\%BUILD%\*.dll C:\src\ServiceStack\release\latest\ServiceStack.Text\
6+
COPY ..\src\ServiceStack.Text\bin\%BUILD%\*.dll C:\src\ServiceStack\release\lib
7+
COPY ..\src\ServiceStack.Text\bin\%BUILD%\*.pdb C:\src\ServiceStack\release\lib

build/ilmerge-all.bat

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/ServiceStack.Text.sln

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceStack.Text", "Servic
55
EndProject
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceStack.Text.Tests", "..\tests\ServiceStack.Text.Tests\ServiceStack.Text.Tests.csproj", "{9770BD40-AA3B-4785-B5E0-F4C470F9F14E}"
77
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{F7FB50ED-EAFF-4839-935A-5BB4A4158245}"
9+
ProjectSection(SolutionItems) = preProject
10+
..\build\build.bat = ..\build\build.bat
11+
EndProjectSection
12+
EndProject
813
Global
914
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1015
Debug|Any CPU = Debug|Any CPU

src/ServiceStack.Text/Env.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static Env()
2323
+ (IsMonoTouch ? " MonoTouch" : "");
2424
}
2525

26-
public static decimal ServiceStackVersion = 1.60m;
26+
public static decimal ServiceStackVersion = 1.61m;
2727

2828
public static bool IsUnix { get; set; }
2929

0 commit comments

Comments
 (0)