本文整理汇总了C#中SerializerSession类的典型用法代码示例。如果您正苦于以下问题:C# SerializerSession类的具体用法?C# SerializerSession怎么用?C# SerializerSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SerializerSession类属于命名空间,在下文中一共展示了SerializerSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadValue
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);
}
示例2: WriteValue
public override void WriteValue(Stream stream, object value, SerializerSession session)
{
//null = 0
// [0]
//length < 255 gives length + 1 as a single byte + payload
// [B length+1] [Payload]
//others gives 254 + int32 length + payload
// [B 254] [I Length] [Payload]
if (value == null)
{
stream.WriteByte(0);
}
else
{
var bytes = Encoding.UTF8.GetBytes((string) value);
if (bytes.Length < 255)
{
stream.WriteByte((byte)(bytes.Length+1));
stream.Write(bytes, 0, bytes.Length);
}
else
{
stream.WriteByte(254);
stream.WriteInt32(bytes.Length);
stream.Write(bytes,0,bytes.Length);
}
}
}
示例3: WriteValue
public override void WriteValue(Stream stream, object value, SerializerSession session)
{
if (value == null)
{
StringSerializer.WriteValueImpl(stream,null,session);
}
else
{
var type = (Type) value;
int existingId;
if (session.Serializer.Options.PreserveObjectReferences && session.TryGetObjectId(type, out existingId))
{
ObjectReferenceSerializer.Instance.WriteManifest(stream, session);
ObjectReferenceSerializer.Instance.WriteValue(stream, existingId, session);
}
else
{
if (session.Serializer.Options.PreserveObjectReferences)
{
session.TrackSerializedObject(type);
}
//type was not written before, add it to the tacked object list
var name = type.GetShortAssemblyQualifiedName();
StringSerializer.WriteValueImpl(stream, name, session);
}
}
}
示例4: WriteValue
public override void WriteValue(Stream stream, object value, SerializerSession session)
{
if (value == null)
{
stream.WriteInt32(-1);
}
else
{
var type = (Type) value;
int existingId;
if (session.Serializer.Options.PreserveObjectReferences && session.TryGetObjectId(type, out existingId))
{
ObjectReferenceSerializer.Instance.WriteManifest(stream, null, session);
ObjectReferenceSerializer.Instance.WriteValue(stream, existingId, session);
}
else
{
//type was not written before, add it to the tacked object list
var name = type.GetShortAssemblyQualifiedName();
if (session.Serializer.Options.PreserveObjectReferences)
{
session.TrackSerializedObject(type);
}
// ReSharper disable once PossibleNullReferenceException
// ReSharper disable once AssignNullToNotNullAttribute
var bytes = Encoding.UTF8.GetBytes(name);
stream.WriteLengthEncodedByteArray(bytes);
}
}
}
示例5: WriteValue
public override void WriteValue(Stream stream, object value, SerializerSession session)
{
var data = decimal.GetBits((decimal) value);
stream.WriteInt32(data[0]);
stream.WriteInt32(data[1]);
stream.WriteInt32(data[2]);
stream.WriteInt32(data[3]);
}
示例6: ReadValue
public override object ReadValue(Stream stream, SerializerSession session)
{
var size = sizeof (long);
var buffer = session.GetBuffer(size);
stream.Read(buffer, 0, size);
var ticks = BitConverter.ToInt64(buffer, 0);
return new DateTime(ticks);
}
示例7: WriteValue
public override void WriteValue(Stream stream, object value, SerializerSession session)
{
var bytes = session.GetBuffer(Int32Serializer.Size);
var data = decimal.GetBits((decimal) value);
Int32Serializer.WriteValueImpl(stream, data[0], bytes);
Int32Serializer.WriteValueImpl(stream, data[1], bytes);
Int32Serializer.WriteValueImpl(stream, data[2], bytes);
Int32Serializer.WriteValueImpl(stream, data[3], bytes);
}
示例8: ReadValue
public override object ReadValue(Stream stream, SerializerSession session)
{
var length = (int) Int32Serializer.Instance.ReadValue(stream, session);
if (length == -1)
return null;
var buffer = session.GetBuffer(length);
stream.Read(buffer, 0, length);
var res = Encoding.UTF8.GetString(buffer, 0, length);
return res;
}
示例9: ReadValue
public override object ReadValue(Stream stream, SerializerSession session)
{
var length = stream.ReadInt32(session);
var array = Array.CreateInstance(_elementType, length); //create the array
for (var i = 0; i < length; i++)
{
var value = stream.ReadObject(session);
array.SetValue(value, i); //set the element value
}
return array;
}
示例10: WriteValue
public override void WriteValue(Stream stream, object value, SerializerSession session)
{
if (value == null)
{
stream.WriteInt32(-1);
}
else
{
var bytes = Encoding.UTF8.GetBytes((string) value);
stream.WriteLengthEncodedByteArray(bytes);
}
}
示例11: WriteValue
public override void WriteValue(Stream stream, object arr, SerializerSession session)
{
var array = arr as Array;
var elementSerializer = session.Serializer.GetSerializerByType(_elementType);
stream.WriteInt32(array.Length);
var preserveObjectReferences = session.Serializer.Options.PreserveObjectReferences;
for (var i = 0; i < array.Length; i++) //write the elements
{
var value = array.GetValue(i);
stream.WriteObject(value, _elementType, elementSerializer, preserveObjectReferences, session);
}
}
示例12: WriteValue
public override void WriteValue(Stream stream, object value, SerializerSession session)
{
var array = value as Array;
var elementType = value.GetType().GetElementType();
var elementSerializer = session.Serializer.GetSerializerByType(elementType);
elementSerializer.WriteManifest(stream, elementType, session); //write array element type
stream.WriteInt32(array.Length);
for (var i = 0; i < array.Length; i++) //write the elements
{
var elementValue = array.GetValue(i);
elementSerializer.WriteValue(stream, elementValue, session);
}
}
示例13: WriteManifest
public override void WriteManifest(Stream stream, Type type, SerializerSession session)
{
if (session.ShouldWriteTypeManifest(type))
{
stream.WriteByte(Manifest);
}
else
{
var typeIdentifier = session.GetTypeIdentifier(type);
stream.Write(new[] { ObjectSerializer.ManifestIndex });
stream.WriteUInt16((ushort) typeIdentifier);
}
}
示例14: WriteManifest
public override void WriteManifest(Stream stream, SerializerSession session)
{
ushort typeIdentifier;
if (session.ShouldWriteTypeManifest(TypeEx.RuntimeType,out typeIdentifier))
{
stream.WriteByte(Manifest);
}
else
{
stream.Write(new[] { ObjectSerializer.ManifestIndex });
UInt16Serializer.WriteValueImpl(stream,typeIdentifier,session);
}
}
示例15: WriteValue
public override void WriteValue(Stream stream, object value, SerializerSession session)
{
if (value == null)
{
stream.WriteInt32(-1);
}
else
{
var type = (Type) value;
var name = type.AssemblyQualifiedName;
var bytes = Encoding.UTF8.GetBytes(name);
stream.WriteLengthEncodedByteArray(bytes);
}
}