當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。