Portable class library allows to serialize/deserialize objects defined in Type Language schemas.
Binaries are available via NuGet package:
PM> Install-Package SharpTL
Declare a class with a TLObject
attribute with unique number for an objects schema. Properties that should be serialized are marked with a TLProperty
attribute with order number.
[TLObject(0xA1B2C3D4)]
public class TestObject
{
[TLProperty(1)]
public bool TestBoolean { get; set; }
[TLProperty(2)]
public double TestDouble { get; set; }
[TLProperty(3)]
public int TestInt { get; set; }
[TLProperty(4)]
public List<int> TestIntVector { get; set; }
[TLProperty(5)]
public long TestLong { get; set; }
[TLProperty(6)]
public string TestString { get; set; }
[TLProperty(7)]
public List<IUser> TestUsersVector { get; set; }
}
The example IUser
interface must be marked by a TLType
attribute with types of derived classes which also must be marked by a TLObject
attribute.
[TLType(typeof (User), typeof (NoUser))]
public interface IUser
{
int Id { get; set; }
}
[TLObject(0xD23C81A3)]
public class User : IUser
{
[TLProperty(1)]
public int Id { get; set; }
[TLProperty(2)]
public string FirstName { get; set; }
[TLProperty(3)]
public string LastName { get; set; }
[TLProperty(4)]
public byte[] Key { get; set; }
}
[TLObject(0xC67599D1)]
public class NoUser : IUser
{
[TLProperty(1)]
public int Id { get; set; }
}
var obj = new TestObject();
// obj properties initializing.
byte[] objBytes = TLRig.Default.Serialize(obj);
byte[] objBytes;
// ...
var obj = TLRig.Default.Deserialize<TestObject>(objBytes);
It is possible to automatically convert a TL-schema to C# object model using the SharpTL.Compiler. It compiles a TL-schema defined in Type Language (or JSON equivalent) to C# object model attributed for using with this serialization library.
There is a special performance measurement tool, named SerializersRace which supports this library.
- Added
TLObjectWithCustomSerializerAttribute
. - Improved compiler:
- Added support for several new built-in types.
- Added 'MethodsInterfaceName' arg to the compiler.
- Compiler template: type interfaces now 'partial's.
- Breaking changes:
TLSerializerBase
now has only one constructor and it acceptsconstructorNumber
.ITLSingleConstructorSerializer
now has settableConstructorNumber
property.- Removed ability to set custom serializer type in
TLObjectAttribute
, useTLObjectWithCustomSerializerAttribute
instead and to override constructor number from a custom serializer, use the attribute together withTLObjectAttribute
.
- Improved performance of
TLVectorSerializer
. - Added
PrepareSerializer<T>()
method to theTLRig
. - Change behavior of getting serializer from
TLRig
. Now result can be null instead of throwing an exception.
- Significantly increased serialization performance of
TLCustomObjectSerializer
(up to 5x faster than in SharpTL 7.0). - Added dependency for the 'Dynamitey' package.
- Added support of the
Object
Pseudotype. - Added generic
TLSerializer<T>
. - Added
CustomSerializerType
support forTLObject
. - TLRig: added serialization/deserialization to/from
TLStreamer
. - Added «Durov mode» to
TLBytesSerializer
. In «Durov mode»Bytes
is an alias forString
type hence both serializers have the same constructor numbers.
- Added support for bare vector serialization in the
TLSchemaCompiler
. - Added
Read()
method with items serialization mode override forTLVerctorSerializer
.
- Fixed problem with zero length on
TLStreamer.WriteRandomData(int length)
. - Changed
TLStreamer
API names conventions (e.g.ReadUInt
->ReadUInt32
).
- Removed
CRC32
(now in theBigMath
lib). - Minor changes to the
TLStreamer
.
- Improved
TLStreamer
. - Added support of serialization mode override to some methods of the
TLRig
. - Renamed
TLStreamer.WriteAllBytes()
toTLStreamer.Write()
.
- Added a
leaveOpen
(underlying stream) parameter toTLStreamer
. - Added
TLBitConverter
. - Implemented serializers for
Int128
andInt256
. Int128
andInt256
base types moved toBigMath
repo.
- Added base types
Int128
,Int256
, andTLBytesSerializer
. - Added
SharpTL.Compiler
.
- Implemented serializers for base TL types and custom objects.