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


C# ProtoWriter.GetTypeKey方法代码示例

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


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

示例1: WriteNetObject

        /// <summary>
        /// Writes an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
        /// </summary>
        public static void WriteNetObject(object value, ProtoWriter dest, int key, NetObjectOptions options)
        {
            Helpers.DebugAssert(value != null);
            bool dynamicType = (options & NetObjectOptions.DynamicType) != 0,
                 asReference = (options & NetObjectOptions.AsReference) != 0;
            WireType wireType = dest.WireType;
            SubItemToken token = ProtoWriter.StartSubItem(null, dest);
            bool writeObject = true;
            if (asReference)
            {
                bool existing;
                int objectKey = dest.NetCache.AddObjectKey(value, out existing);
                ProtoWriter.WriteFieldHeader(existing ? FieldExistingObjectKey : FieldNewObjectKey, WireType.Variant, dest);
                ProtoWriter.WriteInt32(objectKey, dest);
                if (existing)
                {
                    writeObject = false;
                }
            }

            if (writeObject)
            {
                if (dynamicType)
                {
                    bool existing;
                    Type type = value.GetType();
                    key = dest.GetTypeKey(ref type);
                    int typeKey = dest.NetCache.AddObjectKey(type, out existing);
                    ProtoWriter.WriteFieldHeader(existing ? FieldExistingTypeKey : FieldNewTypeKey, WireType.Variant, dest);
                    ProtoWriter.WriteInt32(typeKey, dest);
                    if (!existing)
                    {
                        ProtoWriter.WriteFieldHeader(FieldTypeName, WireType.String, dest);
                        ProtoWriter.WriteString(dest.SerializeType(type), dest);
                    }
                    
                }
                ProtoWriter.WriteFieldHeader(FieldObject, wireType, dest);
                if (value is string)
                {
                    ProtoWriter.WriteString((string)value, dest);
                }
                else { 
                    ProtoWriter.WriteObject(value, key, dest);
                }
            }
            ProtoWriter.EndSubItem(token, dest);
        }
开发者ID:nilavghosh,项目名称:ProtoBuf_Net,代码行数:51,代码来源:BclHelpers.cs

示例2: WriteNetObject

        /// <summary>
        /// Writes an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
        /// </summary>
        public static void WriteNetObject(object value, ProtoWriter dest, int key, NetObjectOptions options)
        {
#if FEAT_IKVM
            throw new NotSupportedException();
#else
            if (dest == null) throw new ArgumentNullException("dest");
            bool dynamicType = (options & NetObjectOptions.DynamicType) != 0,
                 asReference = (options & NetObjectOptions.AsReference) != 0;
            WireType wireType = dest.WireType;
            SubItemToken token = ProtoWriter.StartSubItem(null, dest);
            bool writeObject = true;
            if (asReference)
            {
                bool existing;
                int objectKey = dest.NetCache.AddObjectKey(value, out existing);
                ProtoWriter.WriteFieldHeader(existing ? FieldExistingObjectKey : FieldNewObjectKey, WireType.Variant, dest);
                ProtoWriter.WriteInt32(objectKey, dest);
                if (existing)
                {
                    writeObject = false;
                }
            }

            if (writeObject)
            {
                if (dynamicType)
                {
                    bool existing;
                    Type type = value.GetType();

                    if (!(value is string))
                    {
                        key = dest.GetTypeKey(ref type);
                        if (key < 0) throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
                    }
                    int typeKey = dest.NetCache.AddObjectKey(type, out existing);
                    ProtoWriter.WriteFieldHeader(existing ? FieldExistingTypeKey : FieldNewTypeKey, WireType.Variant, dest);
                    ProtoWriter.WriteInt32(typeKey, dest);
                    if (!existing)
                    {
                        ProtoWriter.WriteFieldHeader(FieldTypeName, WireType.String, dest);
                        ProtoWriter.WriteString(dest.SerializeType(type), dest);
                    }
                    
                }
                ProtoWriter.WriteFieldHeader(FieldObject, wireType, dest);
                if (value is string)
                {
                    ProtoWriter.WriteString((string)value, dest);
                }
                else { 
                    ProtoWriter.WriteObject(value, key, dest);
                }
            }
            ProtoWriter.EndSubItem(token, dest);
#endif
        }
开发者ID:tsuixl,项目名称:Frame,代码行数:60,代码来源:BclHelpers.cs

示例3: WriteNetObject

 public static void WriteNetObject(object value, ProtoWriter dest, int key, BclHelpers.NetObjectOptions options)
 {
     if (dest == null)
     {
         throw new ArgumentNullException("dest");
     }
     bool flag = (byte)(options & BclHelpers.NetObjectOptions.DynamicType) != 0;
     bool flag2 = (byte)(options & BclHelpers.NetObjectOptions.AsReference) != 0;
     WireType wireType = dest.WireType;
     SubItemToken token = ProtoWriter.StartSubItem(null, dest);
     bool flag3 = true;
     if (flag2)
     {
         bool flag4;
         int value2 = dest.NetCache.AddObjectKey(value, out flag4);
         ProtoWriter.WriteFieldHeader((!flag4) ? 2 : 1, WireType.Variant, dest);
         ProtoWriter.WriteInt32(value2, dest);
         if (flag4)
         {
             flag3 = false;
         }
     }
     if (flag3)
     {
         if (flag)
         {
             Type type = value.GetType();
             if (!(value is string))
             {
                 key = dest.GetTypeKey(ref type);
                 if (key < 0)
                 {
                     throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
                 }
             }
             bool flag5;
             int value3 = dest.NetCache.AddObjectKey(type, out flag5);
             ProtoWriter.WriteFieldHeader((!flag5) ? 4 : 3, WireType.Variant, dest);
             ProtoWriter.WriteInt32(value3, dest);
             if (!flag5)
             {
                 ProtoWriter.WriteFieldHeader(8, WireType.String, dest);
                 ProtoWriter.WriteString(dest.SerializeType(type), dest);
             }
         }
         ProtoWriter.WriteFieldHeader(10, wireType, dest);
         if (value is string)
         {
             ProtoWriter.WriteString((string)value, dest);
         }
         else
         {
             ProtoWriter.WriteObject(value, key, dest);
         }
     }
     ProtoWriter.EndSubItem(token, dest);
 }
开发者ID:floatyears,项目名称:Decrypt,代码行数:57,代码来源:BclHelpers.cs


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