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


C# ProtoWriter.Close方法代码示例

本文整理汇总了C#中ProtoWriter.Close方法的典型用法代码示例。如果您正苦于以下问题:C# ProtoWriter.Close方法的具体用法?C# ProtoWriter.Close怎么用?C# ProtoWriter.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProtoWriter的用法示例。


在下文中一共展示了ProtoWriter.Close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SerializeWithLengthPrefix

 /// <summary>
 /// Writes a protocol-buffer representation of the given instance to the supplied stream,
 /// with a length-prefix. This is useful for socket programming,
 /// as DeserializeWithLengthPrefix can be used to read the single object back
 /// from an ongoing stream.
 /// </summary>
 /// <param name="type">The type being serialized.</param>
 /// <param name="value">The existing instance to be serialized (cannot be null).</param>
 /// <param name="style">How to encode the length prefix.</param>
 /// <param name="dest">The destination stream to write to.</param>
 /// <param name="fieldNumber">The tag used as a prefix to each record (only used with base-128 style prefixes).</param>
 public void SerializeWithLengthPrefix(Stream dest, object value, Type type, PrefixStyle style, int fieldNumber)
 {
     if (type == null)
     {
         if(value == null) throw new ArgumentNullException("value");
         type = value.GetType();
     }
     int key = GetKey(ref type);
     using (ProtoWriter writer = new ProtoWriter(dest, this))
     {
         switch (style)
         {
             case PrefixStyle.None:
                 Serialize(key, value, writer);
                 break;
             case PrefixStyle.Base128:
             case PrefixStyle.Fixed32:
             case PrefixStyle.Fixed32BigEndian:
                 ProtoWriter.WriteObject(value, key, writer, style, fieldNumber);
                 break;
             default:
                 throw new ArgumentOutOfRangeException("style");
         }
         writer.Close();
     }
 }
开发者ID:martindevans,项目名称:DistributedServiceProvider,代码行数:37,代码来源:TypeModel.cs

示例2: DeepClone

        /// <summary>
        /// Create a deep clone of the supplied instance; any sub-items are also cloned.
        /// </summary>
        public object DeepClone(object value)
        {
            if (value == null) return null;
            Type type = value.GetType();
            int key = GetKey(ref type);

            if (key >= 0) {
                using (MemoryStream ms = new MemoryStream())
                {
                    using(ProtoWriter writer = new ProtoWriter(ms, this))
                    {
                        Serialize(key, value, writer);
                        writer.Close();
                    }
                    ms.Position = 0;
                    using (ProtoReader reader = new ProtoReader(ms, this))
                    {
                        return Deserialize(key, null, reader);
                    }
                }
            }
            int modelKey;
            if (type == typeof(byte[])) {
                byte[] orig = (byte[])value, clone = new byte[orig.Length];
                Helpers.BlockCopy(orig, 0, clone, 0, orig.Length);
                return clone;
            }
            else if (GetWireType(Type.GetTypeCode(type), DataFormat.Default, ref type, out modelKey) != WireType.None && modelKey < 0)
            {   // immutable; just return the original value
                return value;
            }
            using (MemoryStream ms = new MemoryStream())
            {
                using (ProtoWriter writer = new ProtoWriter(ms, this))
                {
                    if (!TrySerializeAuxiliaryType(writer, type, DataFormat.Default, Serializer.ListItemTag, value)) ThrowUnexpectedType(type);
                    writer.Close();
                }
                ms.Position = 0;
                using (ProtoReader reader = new ProtoReader(ms, this))
                {
                    value = null; // start from scratch!
                    TryDeserializeAuxiliaryType(reader, DataFormat.Default, Serializer.ListItemTag, type, ref value, true, false);
                    return value;
                }
            }
            

        }
开发者ID:martindevans,项目名称:DistributedServiceProvider,代码行数:52,代码来源:TypeModel.cs

示例3: Serialize

 /// <summary>
 /// Writes a protocol-buffer representation of the given instance to the supplied stream.
 /// </summary>
 /// <param name="value">The existing instance to be serialized (cannot be null).</param>
 /// <param name="dest">The destination stream to write to.</param>
 public void Serialize(Stream dest, object value)
 {
     using (ProtoWriter writer = new ProtoWriter(dest, this))
     {
         SerializeCore(writer, value);
         writer.Close();
     }
 }
开发者ID:martindevans,项目名称:DistributedServiceProvider,代码行数:13,代码来源:TypeModel.cs


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