当前位置: 首页>>代码示例>>C#>>正文


C# SerializerSession类代码示例

本文整理汇总了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);
 }
开发者ID:Horusiath,项目名称:Wire,代码行数:7,代码来源:UInt16Serializer.cs

示例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);
         }
         
     }
 }
开发者ID:philiplaureano,项目名称:Wire,代码行数:29,代码来源:StringSerializer.cs

示例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);
         }
     }
 }
开发者ID:akkadotnet,项目名称:Wire,代码行数:27,代码来源:TypeSerializer.cs

示例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);
         }
     }
 }
开发者ID:philiplaureano,项目名称:Wire,代码行数:30,代码来源:TypeSerializer.cs

示例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]);
 }
开发者ID:Horusiath,项目名称:Wire,代码行数:8,代码来源:DecimalSerializer.cs

示例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);
 }
开发者ID:cpx,项目名称:Wire,代码行数:8,代码来源:DateTimeSerializer.cs

示例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);
        }
开发者ID:akkadotnet,项目名称:Wire,代码行数:10,代码来源:DecimalSerializer.cs

示例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;
        }
开发者ID:Horusiath,项目名称:Wire,代码行数:12,代码来源:StringSerializer.cs

示例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;
        }
开发者ID:cpx,项目名称:Wire,代码行数:12,代码来源:ArraySerializer.cs

示例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);
     }
 }
开发者ID:Horusiath,项目名称:Wire,代码行数:12,代码来源:StringSerializer.cs

示例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);
            }
        }
开发者ID:cpx,项目名称:Wire,代码行数:13,代码来源:ArraySerializer.cs

示例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);
     }
 }
开发者ID:Horusiath,项目名称:Wire,代码行数:13,代码来源:ConsistentArraySerializer.cs

示例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);
     }
 }
开发者ID:philiplaureano,项目名称:Wire,代码行数:13,代码来源:TypeSerializer.cs

示例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);
     }
 }
开发者ID:akkadotnet,项目名称:Wire,代码行数:13,代码来源:TypeSerializer.cs

示例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);
     }
 }
开发者ID:Horusiath,项目名称:Wire,代码行数:14,代码来源:TypeSerializer.cs


注:本文中的SerializerSession类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。